几天来我一直在拼命尝试通过一些参数和一个包含PDF的二进制MIME附件来调用soap服务。
我正在使用基于Apache和PHP7的基础架构。我最初尝试使用本机php soapclient类,但我了解该类不允许管理附件。然后,我开始使用php curl复制在Soap-UI上测试的呼叫。
在我看来,呼叫的内容是相同的,但我仍然收到提示错误。
这是呼叫请求设置:
$file = "./CI_test.pdf";
$fileContents = file_get_contents($file);
$url = "https://xxxxxxxx/JProtocolloDocArea/services/DOCAREAProtoSoap";
$boundary = bin2hex ( random_bytes ( 10 ) );
$soap_request = "";
$soap_request .= "\r\n";
$soap_request .= "\r\n";
$soap_request .= "------=_Part_".$boundary;
$soap_request .= "\r\n";
$soap_request .= "Content-Type: text/xml; charset=UTF-8";
$soap_request .= "\r\n";
$soap_request .= "Content-Transfer-Encoding: 8bit";
$soap_request .= "\r\n";
$soap_request .= "Content-ID: <[email protected]>";
$soap_request .= "\r\n";
$soap_request .= "\r\n";
$soap_request .= "<soapenv:Envelope xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" xmlns:tem=\"http://tempuri.org/\">\n";
$soap_request .= " <soapenv:Header/>\n";
$soap_request .= " <soapenv:Body>\n";
$soap_request .= " <tem:inserimento>\n";
$soap_request .= " <strUserName>ESU_PD</strUserName>\n";
$soap_request .= " <strDST>ebFfEeBKYk9yo4jR1M1V8VdSu3VrDpLqK28OzrxiUJvYH83YY4fmAgWUgjmWF2Cb65WTPzN76w5YnKK3OlSss9bva5j29125</strDST>\n";
$soap_request .= " </tem:inserimento>\n";
$soap_request .= " </soapenv:Body>\n";
$soap_request .= "</soapenv:Envelope>";
$soap_request .= "\r\n";
$soap_request .= "------=_Part_".$boundary;
$soap_request .= "\r\n";
$soap_request .= "Content-Type: application/pdf; name=CI_test.pdf";
$soap_request .= "\r\n";
$soap_request .= "Content-Transfer-Encoding: binary";
$soap_request .= "\r\n";
$soap_request .= "Content-ID: <CI_test.pdf>";
$soap_request .= "\r\n";
$soap_request .= "Content-Disposition: attachment; name=\"CI_test.pdf\"; filename=\"CI_test.pdf\"";
$soap_request .= "\r\n";
$soap_request .= "\r\n";
$soap_request .= $fileContents;
$soap_request .= "\r\n";
$soap_request .= "------=_Part_".$boundary."--";
$soap_request .= "\r\n";
这是标题设置:
$header = array(
"Accept-Encoding: gzip,deflate",
"Host: esupd-test.e-pal.it",
"MIME-Version: 1.0",
"Content-Type: multipart/related; type=\"text/xml\"; start=\"<[email protected]>\"; boundary=\"----=_Part_$boundary\"",
"SOAPAction: \"\"",
"Content-Length: ".strlen($soap_request)."",
"Connection: Keep-Alive",
"Cache-Control: no-cache",
"Pragma: no-cache"
);
这就是CURL调用:
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url );
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true );
curl_setopt($ch, CURLOPT_POST, true );
curl_setopt($ch, CURLOPT_POSTFIELDS, $soap_request);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1); // capture the header info
curl_setopt($ch, CURLOPT_VERBOSE, 1); // turn verbose on
$result = curl_exec($ch);
任何建议将不胜感激。
可以认为问题已经解决。
由于服务器接听电话的问题,请求失败。
因此,我报告的PHP脚本可能是对Web服务肥皂进行调用的好方法,该Web服务肥皂包含带有一些参数的XML信封和二进制MIME附件。