PHP CURL将\ 0(NUL字符)添加到方法/错误501方法POST未在RFC 2068中定义

时间:2014-08-03 11:52:41

标签: php post curl http-post fiddler

我有这个与Fiddler一起导出的curl脚本。

curl
-k
-i
--raw
-o 0.dat
-X POST
"https://192.168.178.103/ws/ResourceInteractionService"
-H "Content-Language: en-US"
-H "Content-Type: text/xml"
-H "SOAPAction: setResourceValues"
-H "Cache-Control: no-cache"
-H "Pragma: no-cache"
-H "User-Agent: Java/1.7.0_25"
-H "Host: 192.168.178.103"
-H "Accept: text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2"
-H "Connection: keep-alive"
-H "Cookie: JSESSIONID=-1407060770673-59-927; s_pers=%%20s_fid%%3D3B17498CEA8BA6C4-2186ABA57F7ECAEB%%7C1466279984040%%3B%%20s_vs%%3D1%%7C1403123384042%%3B%%20s_nr%%3D1403121584045-Repeat%%7C1434657584045%%3B;JSESSIONID=-1407060770673-59-927"

这是我的尝试。

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://192.168.178.103/ws/ResourceInteractionService');
curl_setopt($ch, CURLOPT_VERBOSE, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
    'SOAPAction: setResourceValues',
    'Cookie: JSESSIONID=-1407060770673-59-927; s_pers=%%20s_fid%%3D3B17498CEA8BA6C4-2186ABA57F7ECAEB%%7C1466279984040%%3B%%20s_vs%%3D1%%7C1403123384042%%3B%%20s_nr%%3D1403121584045-Repeat%%7C1434657584045%%3B;JSESSIONID=-1407060770673-59-927',
    'Content-Type: text/xml',
    'Content-Language: en-US'
));
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
curl_setopt($ch, CURLOPT_HEADER, true);
curl_setopt($ch, CURLOPT_USERAGENT, 'Java/1.7.0_25');
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false);
curl_setopt($ch, CURLOPT_SSLVERSION, 3);
curl_setopt($ch, CURLOPT_POSTFIELDS, '<?xml version=\'1.0\' encoding=\'UTF-8\'?>
<SOAP-ENV:Envelope xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:SOAP-ENV="http://schemas.xmlsoap.org/soap/envelope/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
<SOAP-ENV:Body>
<ns1:setResourceValues1 xmlns:ns1="utcs">
<ns1:arrayItem xsi:type="ns1:WSResourceValueEnvelope">
<ns1:value xmlns:ns2="utcs.values"  xsi:type="ns2:WSBooleanValue">
<ns2:value xsi:type="xsd:boolean">true</ns2:value>
</ns1:value>

<ns1:typeString xsi:type="xsd:string"></ns1:typeString>

<ns1:resourceID xsi:type="xsd:int">25435</ns1:resourceID>

<ns1:isValueRuntime xsi:type="xsd:boolean">true</ns1:isValueRuntime>
</ns1:arrayItem>
</ns1:setResourceValues1>
</SOAP-ENV:Body>
</SOAP-ENV:Envelope>
');
curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 10);
list($header, $body) = explode("\r\n\r\n", curl_exec($ch), 2);
var_dump($header, $body);
curl_close($ch);

这是响应$ header。

HTTP/1.1 501 Method POST is not defined in RFC 2068 and is not supported by the Servlet API 
content-type: text/html
date: Sun, 03-Aug-2014 11:32:26 GMT
keep-alive: timeout=900, max=1000
connection: Keep-Alive
content-length: 366
server: Rogatkin's JWS based on Acme.Serve/$Revision: 1.39 $
mime-version: 1.0
set-cookie: JSESSIONID=-1407060770673-59-927

这就是回复$ body。

<HTML><HEAD><TITLE>501 Method POST is not defined in RFC 2068 and is not supported by the Servlet API </TITLE></HEAD><BODY BGCOLOR="#F1D0F2"><H2>501 Method POST is not defined in RFC 2068 and is not supported by the Servlet API </H2><HR><ADDRESS><A HREF="http://tjws.sourceforge.net">Rogatkin's JWS based on Acme.Serve $Revision: 1.39 $</A></ADDRESS></BODY></HTML>

这就是调试信息。

* About to connect() to 192.168.178.103 port 443 (#0)
*   Trying 192.168.178.103...
* connected
* Connected to 192.168.178.103 (192.168.178.103) port 443 (#0)
* SSL connection using AES256-SHA
* Server certificate:
*    subject: CN=IHC; O=Schneider Electric; C=FR
*    start date: 2014-01-07 05:21:31 GMT
*    expire date: 2034-01-02 05:21:31 GMT
*    issuer: CN=IHC; O=Schneider Electric; C=FR
*    SSL certificate verify result: self signed certificate (18), continuing anyway.
> POST /ws/ResourceInteractionService HTTP/1.1
User-Agent: Java/1.7.0_25
Host: 192.168.178.103
Accept: */*
SOAPAction: setResourceValues
Cookie: JSESSIONID=-1407060770673-59-927; s_pers=%%20s_fid%%3D3B17498CEA8BA6C4- 2186ABA57F7ECAEB%%7C1466279984040%%3B%%20s_vs%%3D1%%7C1403123384042%%3B%%20s_nr%%3D1403121584045-Repeat%%7C1434657584045%%3B;JSESSIONID=-1407060770673-59-927
Content-Type: text/xml
Content-Language: en-US
Content-Length: 746

* upload completely sent off: 746 out of 746 bytes
< HTTP/1.1 501 Method

在POST之前是&#34; NUL&#34;符号。 也许这就是问题?

0 个答案:

没有答案