2010-08-22 6 views
2

PHP 코드를 상속 받았고 사용중인 서비스가 변경 되었기 때문에 "모든 요청의 HTTP 헤더에 권한을 추가하십시오 ". 나는 무엇을해야할지, 심지어 가능할 지 모르겠다. 관련 코드의모든 요청에 ​​HTTP 헤더를 추가하기 위해 PHP/SOAP 코드 수정하기

일부는 다음과 같습니다

function soap_connect() { 
      $soap_options = array(
        'soap_version' => SOAP_1_2, 
        'encoding' => 'UTF-8', 
        'exceptions' => FALSE 
      ); 
      try { 
        $this->soap_client = new SoapClient($this->configuration['wsdl'], $soap_options); 
      } catch (SoapFault $fault) { 
        return FALSE; 
      } 
      return TRUE; 
    } 

내가 그것을 이해, 그것은 단지 (지금은) 다음과 같은 출력해야한다, 생각 :

Content-Type: application/soap+xml;charset=UTF-8;action="http://ws.testserver.net/nsp/client/hsserve/listHardware" 
Content-Length: 255 
... 

documentatino 말한다 최종 HTTP 요청은 다음과 같아야합니다.

Content-Type: application/soap+xml;charset=UTF-8;action="http://ws.testserver.net/nsp/client/hsserve/listHardware" 
Authorization: WRAP access_token=Z-H7SnqL49eQ2Qp5pLH8k-RVxHfewgIIDt4VCeI2CNnrS4-gBMzPWbfZuMhgvISVV-uTSikS1SqO0n2PRkH3ysQ-uWbvU9podPAm6HiiIS5W2mtpXUfN9ErBmkjF6hDw 
Content-Length: 255 

답변

0

구조의 유형에 서버는 WSDL을 보지 않고 기대하지만, 여기에 몇 가지 예입니다 :

간단한 HTTP 인증보다 고급 사용자 정의 메소드를 구현하는 서버의

$soap_options = array(
       'soap_version' => SOAP_1_2, 
       'encoding'  => 'UTF-8', 
       'exceptions' => FALSE, 
        'login'   => 'username', 
        'password'  => 'password' 
     ); 
     try { 
       $this->soap_client = new SoapClient($this->configuration['wsdl'], $soap_options); 
     } catch (SoapFault $fault) { 
       return FALSE; 
     } 
     return TRUE;  

에게 :

// Namespace for SOAP functions 
$ns   = 'Namespace/Goes/Here'; 

// Build an auth array 
$auth = array(); 
$auth['AccountName'] = new SOAPVar($this->account['AccountName'], XSD_STRING, null, null, null, $ns); 
$auth['ClientCode']  = new SOAPVar($this->account['ClientCode'], XSD_STRING, null, null, null, $ns); 
$auth['Password']  = new SOAPVar($this->account['Password'], XSD_STRING, null, null, null, $ns); 

// Create soap headers base off of the Namespace 
$headerBody = new SOAPVar($auth, SOAP_ENC_OBJECT); 
$header = new SOAPHeader($ns, 'SecuritySoapHeader', $headerBody); 
$client->__setSOAPHeaders(array($header)); 
9

HTTP 호출에 추가 헤더를 제공하기 위해 스트림 컨텍스트를 추가하십시오.

function soap_connect() { 
    $context = array('http' => 
     array(
      'header' => 'Authorization: WRAP access_token=Z-H7SnqL49eQ2Qp5pLH8k-RVxHfewgIIDt4VCeI2CNnrS4-gBMzPWbfZuMhgvISVV-uTSikS1SqO0n2PRkH3ysQ-uWbvU9podPAm6HiiIS5W2mtpXUfN9ErBmkjF6hDw' 
     ) 
    ); 
    $soap_options = array(
     'soap_version' => SOAP_1_2, 
     'encoding' => 'UTF-8', 
     'exceptions' => FALSE, 
     'stream_context' => stream_context_create($context) 
    ); 
    try { 
     $this->soap_client = new SoapClient($this->configuration['wsdl'], $soap_options); 
    } catch (SoapFault $fault) { 
     return FALSE; 
    } 
    return TRUE; 
} 

SoapClient::__construct() 및 자세한 내용은 HTTP context options,

+0

완벽한을 참조하십시오. 네가 할 수 있다는 것도 몰랐어. 감사! –

관련 문제