【问题标题】:How to add ConfigurationName in curl header for SOAP Request如何在 SOAP 请求的 curl 标头中添加 ConfigurationName
【发布时间】:2017-03-27 11:52:12
【问题描述】:

我正在使用 PHP 密码和用户名中的 CURL 处理 SOAP 请求,但需要 API 一个额外的 ConfigurationName 文件,我在 Header 中添加了这个,但响应显示错误

身份验证失败

以下是我的标头代码,请检查:

$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);

请帮助我如何在标题中添加 ConfigurationName 的这个额外值。

【问题讨论】:

  • 您是否尝试将其作为 post 参数发送?
  • 你的意思是在 $xml_post_string 中?
  • 我建议你使用 SoapClient :php.net/manual/en/class.soapclient.php
  • 是的......但我猜 ConfigurationName 所以我猜它不会工作
  • 在 Postman 中工作正常

标签: php api curl soap


【解决方案1】:

我现在很喜欢这个解决方案,我已经在 xml 中设置了 ConfigurationName,如下所示,我的脚本现在正在运行:

$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>';

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-04-10
    • 1970-01-01
    • 2012-10-12
    • 2015-11-02
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多