Important changes to forums and questions
All forums and questions are now archived. To start a new conversation or read the latest updates go to forums.mbed.com.
7 years, 8 months ago.
Problem in parsing head file by HTTPClient library
Just realized that this problem is similar to another thread: http://developer.mbed.org/questions/6087/cause-of-HTTPClient-ERRCould-not-parse-h/
When I tried to run the "GET data" session of HTTPClient_HelloWorld program: http://developer.mbed.org/users/donatien/code/HTTPClient_HelloWorld/
I always get an error code: ret = 3, I believe this has something to do with DNS. Meanwhile, the http status code returned is 200, which I believe is a success.
The page is hosted by xampp on a local computer, I can see the request from mbed in the access log.
If I try to get that page with a raw socket, like what is done in the following program: http://developer.mbed.org/users/mbed_official/code/TCPSocket_HelloWorld/docs/3f8407714419/main_8cpp_source.html
then everything works as it should.
The same happens to POST. I get a error code ret = 3, http status code 200. while I see a success visit in apache access log and the data posted sucessfuly inserted into a MySQL database.
I am thinking that there might be some compatibility issue between HTTP Client library and the updated Ethernet interface. Since last update of HTTP Client library, Ethernet interface has gone through quite a few revisions.
So for those who have the knowledge, if I were to do some trouble shooting, where should I start?
Thanks in advance, ZL
By turning on Debug output to sd card, I narrowed down the problem to "Reading headers" (code between line 325 and 432 in HTTPClient.cpp. Somehow the header file cannot be parsed and the code return prematurely.
The following is the response received(result of raw socket connection):
Received 282 chars from server: HTTP/1.1 200 OK Date: Thu, 29 Jan 2015 20:31:54 GMT Server: Apache/2.4.10 (Win32) OpenSSL/1.0.1i PHP/5.6.3 Last-Modified: Wed, 28 Jan 2015 22:17:43 GMT ETag: "c-50dbdbd86f395" Accept-Ranges: bytes Content-Length: 12 Connection: close Content-Type: text/plain
The following is debug output from httpclient.cpp:
[HTTPClient : DBG]Host: 192.168.1.103 [HTTPClient : DBG]Port: 80 [HTTPClient : DBG]Path: /hello.txt [HTTPClient : DBG]Connecting socket to server [HTTPClient : DBG]Sending request [HTTPClient : DBG]Trying to write 46 bytes [HTTPClient : DBG]Written 46 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 : Date: Thu, 29 Jan 2015 20:30:53 GMT
[HTTPClient : ERR]Could not parse header [HTTPClient : ERR]Protocol error
Not sure what is the actual problem here yet, so if anyone who is willing to lend me hand, you are welcome.
The problem seems only happen to files hosted on a local computer by XAMPP/windows. If the link is substituted by a something on a Ubuntu 14.04 with LAMP stack, everything works fine.
Still not sure what is exactly the problem, most like it has something to do with header format and content.
Question relating to:
7 years, 8 months ago.
(re-posted as an answer)
Regarding to parse error, I got similar problem before, becase buffers size are not big enough in the HTTPClient::connect() member function.
I changed buffers size for key and valie arrays as below: