doushui5587 2017-02-23 09:34
浏览 392

如何从php curl响应中的application / octet-stream数据中检索文档?

I am using php CURL function to retrieve document from my server . In my curl operation i am getting the response as application/octet-stream data .How can i retrieve the document from bellow response? .

--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--

My code for curl operation is

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

Is there any mistake with my code?. Please help .

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 求解答一道线性规划题,用lingo编程运行,第一问要求写出数学模型和lingo语言编程模型,第二问第三问解答就行,我的ddl要到了谁来求了
    • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决
    • ¥50 树莓派安卓APK系统签名
    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果