Php 使用标准xml信封和pdf附件对soap服务的CURL请求

Php 使用标准xml信封和pdf附件对soap服务的CURL请求,php,web-services,curl,soap,attachment,Php,Web Services,Curl,Soap,Attachment,几天来,我一直在拼命尝试使用一些参数和包含PDF的二进制MIME附件调用soap服务 我使用的是基于Apache和PHP7的基础设施。 我最初尝试使用原生php soapclient类,但我知道该类不允许管理附件。然后,我开始用php curl复制在Soap UI上测试的调用 在我看来,调用的内容是相同的,但我继续收到一个soap错误 这是呼叫请求设置: $file = "./CI_test.pdf"; $fileContents = file_get_contents($file); $ur

几天来,我一直在拼命尝试使用一些参数和包含PDF的二进制MIME附件调用soap服务

我使用的是基于Apache和PHP7的基础设施。 我最初尝试使用原生php soapclient类,但我知道该类不允许管理附件。然后,我开始用php curl复制在Soap UI上测试的调用

在我看来,调用的内容是相同的,但我继续收到一个soap错误

这是呼叫请求设置:

$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: <rootpart@soapui.org>";
$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";

任何建议都将不胜感激。

这个问题可以考虑解决

由于接收呼叫的服务器出现问题,请求失败


因此,我报告的PHP脚本是调用webservice soap的一个好方法,该soap包含一个带有一些参数的xml信封和一个二进制MIME附件。

您收到了什么soap错误?不幸的是,处理该错误时会出现一个异常,向我返回一条个性化消息。我不确定请求的头配置和curl配置。你认为它们配置正确吗?我真的不确定。你能把这个异常消息转储吗?谢谢你,马修。。问题解决了。
$header = array(
    "Accept-Encoding: gzip,deflate",
    "Host: esupd-test.e-pal.it",
    "MIME-Version: 1.0",
    "Content-Type: multipart/related; type=\"text/xml\"; start=\"<rootpart@soapui.org>\"; boundary=\"----=_Part_$boundary\"",
    "SOAPAction: \"\"",
    "Content-Length: ".strlen($soap_request)."",
    "Connection: Keep-Alive",
    "Cache-Control: no-cache",
    "Pragma: no-cache"
);
$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);