Post SOAP XML Request
问题描述:
我在尝试几个例子,但似乎没有任何效果。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
为什么我得到这个?
答
如果你使用了网络嗅探器(我会推荐Wireshark),你会发现数据是压缩的。这通常用于服务器端以减少所需的带宽。每个现代浏览器都会自动解压缩,但是你的应用程序不会卷曲。如果您将该字符串保存在文件(例如response.bin
)中并运行file response.bin
,则会看到采用的压缩算法(可能是gzip或deflate)。
为了解决这个问题,请卷曲解压回应你:
curl_setopt($ch,CURLOPT_ENCODING, '');
哇!我永远不会想到这一点...现在它给了我一个可读的响应,但不是我反应的回应:“ns1:Client.NoSOAPAction没有SOAPAction头!cffar23070v04.usdc2.oraclecloud.com”任何想法?谢谢你的帮助! :) – elunap
错误消息说'没有SOAPAction标头。您的XML信封不包含SOAPAction。阅读webservice文档以查看哪些SOAPAction受支持。如果它帮助你,请考虑提供答案。 :) – ThoriumBR