如何在php curl响应中从应用程序/八位字节流数据中检索文档?

如何在php curl响应中从应用程序/八位字节流数据中检索文档?,php,curl,stream,Php,Curl,Stream,我正在使用php CURL函数从服务器检索文档。在curl操作中,我得到的响应是应用程序/八位字节流数据。如何从下面的响应中检索文档 --uuid:9685d4ea-5f71-47d2-938b-04aa830bfc80 Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"; Content-Transfer-Encoding: binary Content-ID: <root.messa

我正在使用php CURL函数从服务器检索文档。在curl操作中,我得到的响应是应用程序/八位字节流数据。如何从下面的响应中检索文档

--uuid:9685d4ea-5f71-47d2-938b-04aa830bfc80
Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml";
Content-Transfer-Encoding: binary
Content-ID: <root.message@cxf.apache.org>

<soap:Envelope xmlns:soap="http://www.w3.org/2003/05/soap-envelope"><soap:Header/><soap:Body><ns17:RetrieveDocumentSetResponse xmlns:ns10="http://docs.oasis-open.org/wsrf/bf-2" xmlns:ns11="http://docs.oasis-open.org/wsn/t-1" xmlns:ns12="urn:gov:hhs:fha:nhinc:common:subscriptionb2overridefordocuments" xmlns:ns13="http://www.hhs.gov/healthit/nhin/cdc" xmlns:ns14="urn:gov:hhs:fha:nhinc:common:subscriptionb2overrideforcdc" xmlns:ns15="http://nhinc.services.com/schema/auditmessage" xmlns:ns16="urn:oasis:names:tc:emergency:EDXL:DE:1.0" xmlns:ns17="urn:ihe:iti:xds-b:2007" xmlns:ns18="http://www.caqh.org/SOAP/WSDL/CORERule2.2.0.xsd" xmlns:ns2="urn:gov:hhs:fha:nhinc:common:nhinccommon" xmlns:ns3="urn:gov:hhs:fha:nhinc:common:nhinccommonentity" xmlns:ns4="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0" xmlns:ns5="urn:oasis:names:tc:ebxml-regrep:xsd:rs:3.0" xmlns:ns6="urn:oasis:names:tc:ebxml-regrep:xsd:query:3.0" xmlns:ns7="urn:oasis:names:tc:ebxml-regrep:xsd:lcm:3.0" xmlns:ns8="http://www.w3.org/2005/08/addressing" xmlns:ns9="http://docs.oasis-open.org/wsn/b-2"><ns5:RegistryResponse status="urn:oasis:names:tc:ebxml-regrep:ResponseStatusType:Success"/><ns17:DocumentResponse><ns17:HomeCommunityId>urn:oid:2.16.840.1.113883.3.1259.10.1003</ns17:HomeCommunityId><ns17:RepositoryUniqueId>1</ns17:RepositoryUniqueId><ns17:DocumentUniqueId>1.RI0004.000000002.D-1</ns17:DocumentUniqueId><ns17:mimeType>text/xml</ns17:mimeType><ns17:Document><xop:Include xmlns:xop="http://www.w3.org/2004/08/xop/include" href="cid:ac0edf1f-3243-43b7-bb59-1beaf4392ebc-24@urn%3Aihe%3Aiti%3Axds-b%3A2007"/></ns17:Document></ns17:DocumentResponse></ns17:RetrieveDocumentSetResponse></soap:Body></soap:Envelope>
--uuid:9685d4ea-5f71-47d2-938b-04aa830bfc80
Content-Type: application/octet-stream
Content-Transfer-Encoding: binary
Content-ID: <ac0edf1f-3243-43b7-bb59-1beaf4392ebc-24@urn:ihe:iti:xds-b:2007>

P-000000002
D-000000002.1
--uuid:9685d4ea-5f71-47d2-938b-04aa830bfc80--
我的密码有错误吗?。请帮忙

$body = file_get_contents(dirname(__FILE__).'/doc_retrieve.xml');

$headers = array( 
    'Content-Type: text/xml; charset="utf-8"', 
    'Content-Length: '.strlen($body), 
    'Accept: text/xml', 
    'Cache-Control: no-cache', 
    'Pragma: no-cache', 
    'SOAPAction: "RespondingGateway_CrossGatewayRetrieve"'
);
$ch = curl_init("http://testserver:8080/Gateway/DocumentRetrieve/3_0/EntityService/EntityDocRetrieve?wsdl");
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 
curl_setopt($ch, CURLOPT_TIMEOUT, 60); 
curl_setopt($ch, CURLOPT_BINARYTRANSFER, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_USERAGENT, $defined_vars['HTTP_USER_AGENT']);
curl_setopt($ch, CURLOPT_SSLVERSION, CURL_SSLVERSION_TLSv1_2);
// Stuff I have added
curl_setopt($ch, CURLOPT_POST, true); 
curl_setopt($ch, CURLOPT_POSTFIELDS, $body); 
curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_BASIC);
$response   = curl_exec($ch);
$filename=time();
header('Content-Transfer-Encoding: binary');
header('Accept-Ranges: bytes');  
header('Content-Encoding: none');
header('Content-Type: application/.dat');  
header('Content-Disposition: attachment; filename='.$filename.'.dat');  
$destination = dirname(__FILE__) . '/'.$filename.'.dat';
$file = fopen($destination, "w+");
fputs($file, $response);
fclose($file);
readfile($destination); 
die();