tags:

views:

64

answers:

1

Hey Guys I am getting some extra characters like '5ae' and '45c' interspersed along with valid data when using http_post_data. 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.

A: 

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

Pascal MARTIN