2017-03-27 264 views
2

我正在使用PHP中的CURL密碼和用戶名處理SOAP請求,但需要API一個額外提交的ConfigurationName,我已將此添加到頭中,但響應顯示我的如何在curl頭中爲SOAP請求添加ConfigurationName

FailedAuthentication

以下的錯誤是我的頭代碼,請檢查:

$headers=array(
"Content-type:text/xml;charset=\"utf-8\"", 
"Accept:text/xml", 
"Cache-Control:no-cache", 
"Pragma:no-cache", 
"SOAPAction:\"actionurl\"", 
"Content-length:".strlen($xml_post_string), 
"ConfigurationName: ConfigurationName", 
); 

$url=$soapUrl; 
$ch=curl_init(); 
curl_setopt($ch,CURLOPT_SSL_VERIFYPEER,0); 
curl_setopt($ch,CURLOPT_URL,$url); 
curl_setopt($ch,CURLOPT_RETURNTRANSFER,true); 
curl_setopt($ch,CURLOPT_USERPWD,$soapUser.":".$soapPassword);//usernameandpassword-declaredatthetopofthedoc 
curl_setopt($ch,CURLOPT_HTTPAUTH,CURLAUTH_ANY); 
curl_setopt($ch,CURLOPT_TIMEOUT,100); 
curl_setopt($ch,CURLOPT_POST,true); 
curl_setopt($ch,CURLOPT_POSTFIELDS,$xml_post_string);//theSOAPrequest 
curl_setopt($ch,CURLOPT_HTTPHEADER,$headers); 

認罪se幫助我如何在頭文件中添加這個額外的ConfigurationName值。

+0

你嘗試發送它作爲後PARAM? –

+0

你的意思是$ xml_post_string? –

+1

我建議你使用SoapClient:http://php.net/manual/en/class.soapclient.php – Elbarto

回答

3

我喜歡這個解決方案,現在我已經設置了ConfigurationName像下面的XML,現在我的腳本工作:

$xml_post_string .='<soap:Header>'; 
$xml_post_string .='<UserID></UserID>'; 
$xml_post_string .='<Password></Password>'; 
$xml_post_string .='<ConfigurationName></ConfigurationName>'; 
$xml_post_string .='</soap:Header>';