下面的curl命令运行良好。
curl --标题“内容-类型: application/soap+xml”--标题"Accept: text/xml“-标头"SOAPAction:‘”--数据-二进制@signedSoapRequest.xml http://server:8081/WebService
我正试图使用curl从PHP复制相同的内容,如下所示。但是错误代码403失败了。
$message = <?xml version="1.0"....signed xml data...</SOAP-ENV:Envelope>
$headers = array(
"Content-type: text/xml;charset=\"utf-8\"",
"Accept: text/xml",
"Cache-Control: no-cache",
"Pragma: no-cache",
"SOAPAction: ''",
"Content-length: ".strlen($message),
);
$result = array();
$ch = curl_init();
curl_setopt($ch, CURLOPT_VERBOSE, false);
curl_setopt($ch, CURLOPT_URL, $this->endpoint);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 30);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, TRUE);
curl_setopt($ch, CURLOPT_POSTFIELDS, $message);
$result['soap_result'] = $this->cleanXML(curl_exec($ch));如果在$message中存储一个简单的xml,而不是像下面的curls命令那样存储签名的xml数据。curl --标题“内容-类型: application/soap+xml”--标题"Accept: text/xml“-标头"SOAPAction:‘”--data @SoapRequest.xml http://server:8081/WebService
对于这个curl coommand,PHP代码工作得很好。由于这个curl命令使用--data标志,它意味着一个文本文件/数据,而不是二进制/签名数据。
是否知道如何使用签名的xml。我试着设置内容类型:applicaton/octet,但是同样的403错误。(403)禁止
发布于 2021-05-31 19:11:45
代码curl_setopt($ch,CURLOPT_POSTFIELDS,$message);替换为curl_setopt($ch,CURLOPT_POSTFIELDS,file_get_contents('soapRequest.xml'))
它开始正常工作了。
而不是在$message变量中指定文件的值,然后在CURLOPT_POSTFIELDS中设置$message,现在使用file_get_contents()读取文件并设置CURLOPT_POSTFIELDS。
https://stackoverflow.com/questions/67743754
复制相似问题