Custom header using PHP soap functions

你离开我真会死。 提交于 2019-12-04 03:14:08

I needed something similar and was able to use an XSD_ANYXML SoapVar to achieve this:

    $auth = "<username>$username</username>";
    $auth .= "<password>$password</password>";
    $auth_block = new SoapVar( $auth, XSD_ANYXML, NULL, NULL, NULL, NULL );

    $header = new SoapHeader( 'http://schemas.xmlsoap.org/soap/envelope/', 'Header', $auth_block );
    $soap_client->__setSoapHeaders( $header );

This resulted in:

<SOAP-ENV:Header>
   <username>12345</username>
   <password>12</password>
</SOAP-ENV:Header>

In your example, you are creating only one SoapHeader entry (with namespace, but named 'null'). Your desired result contains two separate header entries (without namespace), so you might try:

$headers = array();
$headers[] = new SoapHeader(NULL, 'USER', $auth->USER);
$headers[] = new SoapHeader(NULL, 'PASSWORD', $auth->PASSWORD);

You'd then pass the $headers array to the soap call (either directly, or upfront via __setSoapHeaders).

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!