
__setSoapHeaders 메서드는 SoapClient 클래스의 메서드 중 하나로, SOAP 요청에 헤더를 추가하는 데 사용됩니다. 이 메서드는 SoapHeader 개체를 받는데, 이 개체에는 다음과 같은 속성이 있습니다.
- namespace: 헤더의 네임스페이스
- name: 헤더의 이름
- value: 헤더의 값
SoapClient 클래스를 사용하여 SOAP 요청을 보내는 경우, 헤더를 설정하는 방법은 다음과 같습니다.
1. SoapHeader 개체를 생성합니다. 예를 들어, 다음과 같이 생성할 수 있습니다.
#hostingforum.kr
php
$header = new SoapHeader('http://example.com/namespace', 'Authorization', 'Basic XXXXXX');
2. SoapClient 클래스의 __setSoapHeaders 메서드를 호출하여 헤더를 설정합니다. 예를 들어, 다음과 같이 호출할 수 있습니다.
#hostingforum.kr
php
$soapClient->setSoapHeaders(array($header));
3. SOAP 요청을 보내는 메서드를 호출합니다. 예를 들어, 다음과 같이 호출할 수 있습니다.
#hostingforum.kr
php
$result = $soapClient->call('methodName');
위의 예에서, 헤더를 다음과 같이 설정합니다.
#hostingforum.kr
php
$soapClient->setSoapHeaders(array(
'Authorization' => 'Basic XXXXXX',
'Content-Type' => 'text/xml; charset=utf-8'
));
이 코드는 SOAP 요청에 Authorization 헤더와 Content-Type 헤더를 추가합니다. Authorization 헤더의 값은 'Basic XXXXXX'이며, Content-Type 헤더의 값은 'text/xml; charset=utf-8'입니다.
2025-08-09 03:58