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.
9 years, 10 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
Update:
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
hello world!
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.
Update 2:
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:
1 Answer
9 years, 10 months ago.
Hi,
(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:
http://developer.mbed.org/users/MACRUM/code/HTTPClient/file/3c7789c521df/HTTPClient.cpp
I'm also seeing that the GET request on the HTTPClient_HelloWorld program isn't working, even after you update all of the libraries. I found that if I changed the URL to pretty much anything else though it seemed to work. I've been using http://api.ipify.org/ as a simple test, although I haven't tested a locally hosted page. Can you confirm that you're seeing the same thing?
Thanks, Brian
posted by Brian Daniels 29 Jan 2015Yes, if I try to access http://api.ipify.org/ from mbed, I can see my IP address the same as it is displayed in a browser. The trick must be in header itself because that is where the error code come from. I will try to see what is in your header, mine and also the link in the example.
posted by Zhiyong Li 29 Jan 2015Hi,
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:
http://developer.mbed.org/users/MACRUM/code/HTTPClient/file/3c7789c521df/HTTPClient.cpp
posted by Toyomasa Watarai 30 Jan 2015Hi Toyomasa, Thanks pointing this out. This does make a lot of sense. The longest value Server has 46 letters in my case, that explains why the parsing stops after Date and at Server. Why don't post your comment as answer? That way it will not be buried in comments and other user can easily see it.
Thanks, ZL
posted by Zhiyong Li 30 Jan 2015