2017-09-01 78 views
0

我在嘗試幾個例子,但似乎沒有任何效果。Post SOAP XML Request

我需要發送該包絡的要求:

<soapenv:Envelope xmlns:soapenv="http://www.w3.org/2003/05/soap-envelope" xmlns:v2="http://xmlns.oracle.com/oxp/service/v2"> 
    <soapenv:Header /> 
<soapenv:Body> 
    <v2:runReport> 
    <v2:reportRequest> 
    <v2:attributeLocale>en-US</v2:attributeLocale> 
    <v2:attributeTemplate>Default</v2:attributeTemplate> 
    <v2:reportAbsolutePath>/Custom/Financials/Fac/XXIASA_FAC.xdo</v2:reportAbsolutePath> 
    <v2:dynamicDataSource xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> 
    <v2:parameterNameValues xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> 
    <v2:XDOPropertyList xsi:nil="true" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" /> 
    </v2:reportRequest> 
    <v2:userID>user</v2:userID> 
    <v2:password>password</v2:password> 
    </v2:runReport> 
    </soapenv:Body> 
    </soapenv:Envelope> 

這是我的代碼:

$url = 'https://soapurl/v2/ReportService?WSDL'; 

    $headers = array("Content-type: application/soap+xml; charset=\"utf-8\"", "Content-length: " . strlen($xml)); 

    $ch = curl_init(); 

    curl_setopt($ch, CURLOPT_URL, $url); 
    curl_setopt($ch, CURLOPT_HTTPAUTH, CURLAUTH_ANY); 
    curl_setopt($ch, CURLOPT_HTTPHEADER, $headers); 
    curl_setopt($ch, CURLOPT_POST, true); 
    curl_setopt($ch, CURLOPT_POSTFIELDS, $xml); 
    curl_setopt($ch, CURLOPT_TIMEOUT, 30); 
    curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); 

    $response = curl_exec($ch); 
    print_r($response); 

這是怪異的結果我得到回:

��R;o�0��+\ﱁTj�QZ�S_R���m�%sF�@��k�Q�l�����lwjT紅�$�H��Rñ���6OxW2gy�`�_aPƶ �|�\{��:Q��;�S���H���EG�<9���q$�v&gI�ҟ���l��6y��yB���?[��x���X5�a��6��5& ��<8�Q���e`�/F+������{���]������K�(2Q��T���X(�F*ϵ�k��eym����Ӊ��]�M�!y ��"m.�����0z�|�1���g�����}� ������C 

爲什麼我得到這個?

回答

1

如果你使用了網絡嗅探器(我會推薦Wireshark),你會發現數據是壓縮的。這通常用於服務器端以減少所需的帶寬。每個現代瀏覽器都會自動解壓縮,但是你的應用程序不會捲曲。如果您將該字符串保存在文件(例如response.bin)中並運行file response.bin,則會看到採用的壓縮算法(可能是gzip或deflate)。

爲了解決這個問題,請捲曲解壓回應你:

curl_setopt($ch,CURLOPT_ENCODING, ''); 
+0

哇!我永遠不會想到這一點...現在它給了我一個可讀的響應,但不是我反應的迴應:「ns1:Client.NoSOAPAction沒有SOAPAction頭!cffar23070v04.usdc2.oraclecloud.com」任何想法?謝謝你的幫助! :) – elunap

+1

錯誤消息說'沒有SOAPAction標頭。您的XML信封不包含SOAPAction。閱讀webservice文檔以查看哪些SOAPAction受支持。如果它幫助你,請考慮提供答案。 :) – ThoriumBR