簡體   English   中英

如何使用PHP-curl發送對“多部分/相關”內容類型的請求?

[英]How to send request for “multipart/related” Content-Type using PHP-curl?

以下是肥皂信封和標題信息:

    POST /tf6/services/xdsrepositoryb HTTP/1.1
    Content-Type: multipart/related; 
    boundary=MIMEBoundaryurn_uuid_566EAD10FEBB55C5A61257193478449; 
    type="application/xop+xml"; start="
    <0.urn:uuid:566EAD10FEBB55C5A61257193478450@apache.org>"; start-
    info="application/soap+xml"; 
    action="urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b"

    --MIMEBoundaryurn_uuid_566EAD10FEBB55C5A61257193478449
    Content-Type: application/xop+xml; charset=UTF-8; type="application/soap+xml"
    Content-Transfer-Encoding: binary
    Content-ID: <0.urn:uuid:566EAD10FEBB55C5A61257193478450@apache.org>

    <?xml version='1.0' encoding='UTF-8'?>
    <soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope"
        xmlns:wsa="http://www.w3.org/2005/08/addressing">
        <soapenv:Header>
            <wsa:To>http://localhost:5000/tf6/services/xdsrepositoryb</wsa:To>
            <wsa:MessageID soapenv:mustUnderstand="true">urn:uuid:566EAD10FEBB55C5A61257193478400</wsa:MessageID>
            <wsa:Action>urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b</wsa:Action>
        </soapenv:Header>
        <soapenv:Body>
            <xdsb:ProvideAndRegisterDocumentSetRequest xmlns:xdsb="urn:ihe:iti:xds-b:2007">
     <lcm:SubmitObjectsRequest xmlns:lcm="urn:oasis:names:tc:ebxml-regrep:xsd:lcm:3.0">
                    <rim:RegistryObjectList xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0">
                        <rim:ExtrinsicObject id="Document01" mimeType="text/plain"
                            objectType="urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1">
     </lcm:SubmitObjectsRequest>
      <xdsb:Document id="Document01">
                    <xop:Include href="cid:1.urn:uuid:566EAD10FEBB55C5A61257193478499@apache.org"
                        xmlns:xop="http://www.w3.org/2004/08/xop/include"/>
                </xdsb:Document>
            </xdsb:ProvideAndRegisterDocumentSetRequest>
        </soapenv:Body>
    </soapenv:Envelope>

    --MIMEBoundaryurn_uuid_566EAD10FEBB55C5A61257193478449
    Content-Type: text/plain
    Content-Transfer-Encoding: binary
    Content-ID: <1.urn:uuid:566EAD10FEBB55C5A61257193478499@apache.org>
    This is my document.
    It is great!
    --MIMEBoundaryurn_uuid_566EAD10FEBB55C5A61257193478449--

如何使用CURL編寫PHP腳本來發送請求?

每當我嘗試致電服務時,我都會收到HTTP-400錯誤,請告知。

謝謝。

這是我正在嘗試的代碼:

 $body= $body = '<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
<s:Header>
    <a:Action s:mustUnderstand="1">urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b</a:Action>
    <a:From>
        <a:Address>urn:oid:2.16.840.1.113883.3.1259.10.1003</a:Address>
    </a:From>
    <a:To>https://CDACert.hawaiihie.org:20000/repository</a:To>
</s:Header>
<s:Body>
    <ProvideAndRegisterDocumentSetRequest xmlns="urn:ihe:iti:xds-b:2007" xmlns:xop="http://www.w3.org/2004/08/xop/include">
        <lcm3:SubmitObjectsRequest xmlns:lcm3="urn:oasis:names:tc:ebxml-regrep:xsd:lcm:3.0" xmlns:rim="urn:oasis:names:tc:ebxml-regrep:xsd:rim:3.0">
            <rim:RegistryObjectList>
                <rim:ExtrinsicObject id="Document1" mimeType="text/xml" objectType="urn:uuid:7edca82f-054d-47f2-a032-9b2a5b5186c1">
                </rim:Association>
            </rim:RegistryObjectList>
        </lcm3:SubmitObjectsRequest>
        <Document id=\"Document1\">
                <xop:Include href="cid:test_ID_123"
                xmlns:xop="http://www.w3.org/2004/08/xop/include"/></Document>
    </ProvideAndRegisterDocumentSetRequest>
</s:Body>

“;

 $text = 'dGhpcyBpcyBTaGl2J3MgZG9j';// base64 of content
 $boundary  = 'MIMEBoundaryurn_uuid_'.uniqid();
 $postData = "--$boundary\n"
     ."Content-Type: application/xop+xml; charset=UTF-8; type=\"application/soap+xml\n"
     ."Content-Transfer-Encoding: binary\n"
     ."Content-length:".strlen($body)."\n"
     ."Content-ID:test_start\n"
     .$body."\n\n"
     ."--$boundary\n"
     ."Content-Type: text/plain;\n"
     ."Content-Transfer-Encoding: binary\n"
     ."Content-length:".strlen($text)."\n"
     ."Content-ID:test_ID_123\n"
     .$text."\n"
     ."--$boundary--";
 $header1 = array (
          "Content-Type: multipart/related; type=\"application/xop+xml\"; start=\"test_start\"; start-info=\"application/soap+xml\"; action=\"urn:ihe:iti:2007:ProvideAndRegisterDocumentSet-b\"",
          "Content-length:".strlen($postData),
          "Transfer-Encoding:chunked",
          "User-Agent:" .$_SERVER ['HTTP_USER_AGENT'],
          "Host:" .$_SERVER['HTTP_HOST']
     );
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $soapUrl);
curl_setopt($ch, CURLINFO_HEADER_OUT, 1);
curl_setopt($ch, CURLINFO_, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header1);
curl_setopt($ch, CURLOPT_HEADER, 1);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, array($postData)); // the SOAP request
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$response = curl_exec($ch); // 400 HTTP error from curl_info

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM