我正在使用soap客戶端連接到wsdl服務。肥皂客戶端使用自定義身份驗證模式,我將它們添加到http通過以下代碼PHP soapclient使用代理與身份驗證和自定義http標頭
$client=new SoapClient(
$wsdl,
array(
'trace' => 1,
"stream_context" => stream_context_create(
array(
"http"=>array(
"header"=> "username: xmluatbank\r\n".
"password: 123456\r\n"
)
)
)
);
並且標頭如下所示。
POST /myweb/Proxy HTTP/1.1
Host: uat.myweb.com:8080
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.4.19
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 1086
username: xmluatbank
password: 123456
到目前爲止,直到這裏一切都很好,然後來到新的請求需要通過代理服務器連接,所以我改變了代碼follwing:
$client=new SoapClient(
$wsdl,
array(
'trace' => 1,
"stream_context" => stream_context_create(
array(
"http"=>array(
"header"=> "username: xmluatbank\r\n".
"password: 123456\r\n"
)
),
'proxy_host' => $proxy,
'proxy_port' => $proxyport,
'proxy_login' => $proxyusrname,
'proxy_password' => $proxypwd,
)
);
和標題變成這個樣子:
POST http://uat.myweb.com:8080/ctos/Proxy HTTP/1.1
Host: uat.myweb.com:8080
Connection: Keep-Alive
User-Agent: PHP-SOAP/5.3.9-ZS5.6.0
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 1086
Proxy-Authorization: Basic YWdyb2JhbmtcanVyaXMudnRjbDpBYmNkMTIx==
因爲您可以看到我現在擁有的流上下文已經消失,所以現在我得到了wsdl服務器的認證錯誤。看起來像代理覆蓋HTTP標頭。所以我試圖代理添加到HTTP頭,而不是使用SOAP代理
$sLogin = base64_encode("$proxyusername:$proxypwd");
$aHTTP['http']['proxy'] = "$proxy:$proxyprot";
$aHTTP['http']['method'] = 'POST';
$aHTTP['http']['header'] = "User-Agent: My PHP Script\r\n";
$aHTTP['http']['header'] .= "Proxy-Authorization: Basic $sLogin";
$aHTTP['http']['header'] .= "username: xmluatbank\r\n"."password: 1234567\r\n";
$context = stream_context_create($aHTTP);
並稱爲SOAP客戶端這樣的:
$client=new SoapClient(
$wsdl,
array(
'trace' => 1,
"stream_context" => $context
)
);
但這樣一來我得到肥皂錯誤,無法連接到代理。
SOAP-ERROR: Parsing WSDL: Couldn't load from 'http://uat.myweb.com:8080/ctos/Proxy?wsdl' : failed to load external entity "http://uat.myweb.com:8080/myweb/Proxy?wsdl"
我不知道如何解決這個問題。我嘗試了所有我知道,請大家幫忙
什麼是對舊版本的PHP '$ proxy'的價值?使用捲曲或類似方法時,你能獲得wsdl嗎?示例'curl -X POST --proxy'http:// proxyuser:proxypass @ proxyaddr:proxyport'-H'用戶名:xmluatbank'-H'密碼:123456''http://uat.myweb.com:8080/myweb/Proxy?wsdl'' – piotrekkr 2014-09-25 10:43:34
不幸的是,銀行正在使用Windows服務器 – 2014-09-25 12:21:19
您可以像這裏描述的那樣使用vbscript/powershell http://stackoverflow.com/questions/2710748/run-curl-commands-from-windows-console – piotrekkr 2014-09-25 12:57:31