开发者

http_post_data adding extra characters in response

Hey Guys I am getting some extra characters like '5ae' and '45c' interspersed along with valid data when using http_post_dat开发者_运维百科a. The data I am sending is XML and so is the response. The response contains these weird characters thats making the XML invalid. If I use fsockopen I do not have this issue. Would really like some input on this.


Your question is not giving much details, but (quite a wild guess, but this reminds me of that) this could related to Chunked transfer encoding (quoting) :

If a Transfer-Encoding header with a value of chunked is specified in an HTTP message, the body of the message is made of an unspecified number of chunks ending with a last, zero-sized, chunk.

Each non-empty chunk starts with the number of octets of the data it embeds (size written in hexadecimal) followed by a CRLF (carriage return and line feed), and the data itself.


The 5ae and 45c you're getting in your data could correspond to the size of each chunk.

If you are trying to send HTTP requests by hand, that might no be such a good idea : HTTP is not such an easy protocol, and you should use already-existing libraries that will deal with those kind of troubles for you.

For instance, you could take a look at curl -- see curl_setopt for the impressive list of possible options.


Edit : I realize that http_post_data is a function provided by the PECL http extension.

There's a function that might interest you, in that library, to decode chunked data : http_chunked_decode


Yes, it is a result of Chucked Transfer Encoding. We may observe this behavior in fiddler by unchecking the 'Chunked Transfer-Encoding' in the Transformer tab of response pane.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜