9 years, 3 months ago.

cause of [HTTPClient : ERR]Could not parse header ?

Hi, I am trying our your example and HTTPClient library on FRDM-K64F with very latest library revisions (ethernetInterface v45, HTTPClient v18, mbed-rtos v62, mbed v92)

With a sockets example, I am able to get the hello world text file from developer.mbed.org. It also seems to get the response from the server with the HTTPClient library, however there is a problem with the header processing.

Any ideas?

This request: int ret = http.get("http://developer.mbed.org/media/uploads/donatien/hello.txt", str, 128);

Results in this:

Trying to fetch page... [HTTPClient : DBG]Scheme: http [HTTPClient : DBG]Host: developer.mbed.org [HTTPClient : DBG]Port: 80 [HTTPClient : DBG]Path: /media/uploads/donatien/hello.txt [HTTPClient : DBG]Connecting socket to server [HTTPClient : DBG]Sending request [HTTPClient : DBG]Trying to write 74 bytes [HTTPClient : DBG]Written 74 bytes [HTTPClient : DBG]Sending headers [HTTPClient : DBG]Headers sent [HTTPClient : DBG]Trying to write 2 bytes [HTTPClient : DBG]Written 2 bytes [HTTPClient : DBG]Receiving response [HTTPClient : DBG]Trying to read between 1 and 255 bytes [HTTPClient : DBG]Trying to read at most 1 bytes [Blocking] [HTTPClient : DBG]Trying to read at most 254 bytes [Not blocking] [HTTPClient : DBG]Read 255 bytes [HTTPClient : DBG]Reading headers [HTTPClient : DBG]Read header : Server: nginx/1.4.6 (Ubuntu)

[HTTPClient : DBG]Read header : Date: Wed, 28 Jan 2015 14:43:51 GMT

[HTTPClient : DBG]Read header : Content-Type: text/plain

[HTTPClient : DBG]Read header : Content-Length: 12

[HTTPClient : DBG]Read header : Connection: keep-alive

[HTTPClient : ERR]Could not parse header [HTTPClient : ERR]Protocol error Error - ret = 3 - HTTP return code = 200

Question relating to:

Simple example demonstrating how to use GET & POST requests with the HTTP Client client, http, networking

Hi Mac,

It seems we are facing the same issue. http://developer.mbed.org/questions/6101/Problem-in-parsing-head-file-by-HTTPClie/

Did you make any progress on this?

My understanding is, the library looks for Content-Length etc in the first 255 bytes of response, if not found, then throws an error.

I will try to take some fields out of the header file and see if that does the trick.

posted by Zhiyong Li 29 Jan 2015

Hi, No, I haven't made progress on it. I am an HTTP novice, but I can't find a requirement for including the content-length header in the first 255 bytes of the response. maybe that is a special normal condition for embedded device communication. I really don't know what might have changed in the new ethernetinterface that could have changed the behavior in regards to parsing the headers. Hopefully, someone with more expertise can help!

posted by Mac Lobdell 30 Jan 2015

Hi Mac,

In case you still have problems with HTTPClient. please check the answer provided by Toyomasa at the end of the following thread: http://developer.mbed.org/questions/6101/Problem-in-parsing-head-file-by-HTTPClie/

Toyomasa also released a patched version of HTTPClient library: http://developer.mbed.org/users/MACRUM/code/HTTPClient/file/3c7789c521df/HTTPClient.cpp

posted by Zhiyong Li 13 Feb 2015
Be the first to answer this question.