-
Notifications
You must be signed in to change notification settings - Fork 13.3k
HTTPClient unable to read returned Headers #1368
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
Thanks, but it still returns empty.
When looking at a WireShark capture, there are a number of headers ahead of the "normal" data:
But the code returns:
|
I suppose collectHeaders should be called before http.POST, because the On Tue, Jan 5, 2016 at 1:08 PM, supersjimmie [email protected]
|
(our comments crossed) Oh, no... And then, just after reading it all again, I realized what I did wrong. |
Now I see that, in a next stage, the server responds with 2 identical named headers: |
no, the handling is the same as the Webserver uses and is not designed of this usage. |
Sorry, it is not my server. (I am the client in Europe, requesting solar data from a server in China) |
So, for now I hav done a quick and very dirty change to my local version to add:
(including about everything else needed) |
the http client gives you no direct access to the header. to: _currentHeaders[i].value += headerValue + "; "; and you get at least all data, as workaround it will work but its no solution for the core. Note: |
Yes sorry I sometimes type a second message after my previous message and then our messages cross. Since I do not understand dynamically allocating memory and things like that, I now assume only 2 _cookies. and to be safe I use String _cookies[4]; So, in the .h file, just below the size_t headerCount;
and in HTTPClient::handleHeaderResponse():
And also 2 new functions:
I could try to figure out how to prevent an overflow, or just limit the cookieCount to a max of 4. |
may add: if(_cookieCount < 4) to be sure not to use the array out of its borders, |
Thanks, your change: But because this solution only requires one small change in one file, I guest it is better than my solution to filter all Set-Cookies to a separate series of Strings. |
Could there be something changed in the latest version that broke the cookies? When I return to the older version, it works fine again. |
2.1.0-rc1 has SDK 1.5.0 this one has some bugs. |
Git version is just the zip that can be downloaded here? |
when you mean: |
Confirm. I downloaded that today and only changed that one line. To be precise, I use Arduino IDE 1.6.5 with the old version and 1.6.7 with the new version. |
#define HTTPC_ERROR_CONNECTION_REFUSED (-1) the connect to the server failed, I think you change has no effect on the -1 result. |
Ok, I will do a packet trace tomorrow to see what happens exactly. |
It is very strange... When I look at wireshark: 1a. I send a POST with the login details 2a. I send a GET, together with the session cookies and a data request If I then just try http.getString() it is empty, offcourse. I do not know very much about packets, but I notice a small difference. In the non working part, the ESP sends a packet with FIN,ACK: EDIT: In addition, the third and last session normally depends on the first two, but if I just fake the second session, the third session seems to be successful again. This all tested many times over and over... Same results, old passes, new fails on the second session. |
the ESP closes the connection: try to enable the debug for the HTTPClient. |
I would love to, but there is no Debug Port option in my IDE Tools-menu. |
GIT and 2.1.0-rc1 have the menu independent of the installing method. |
Figured it out, the debug options are only available with board "generic esp8266 module". |
Here is the complete list with all 3 requests:
(don't look at the '1234' id's and don't compare the cookies, I removed some parts for safety) |
Removed |
the server sends two times a 0 byte chunk this is not good (not in the RFC like this) while(_tcp->available() > 0) {
_tcp->read();
} to clear the buffer before next request |
#1368 (comment) |
Thanks for #1368 with: |
the |
I think another way to do this is to change RequestArgument structure to maintain a linked list of values instead of one String value. However you would also have to provide a way to iterate over values for the given key, potentially changing the signatures of existing methods (i.e. headers(name)) |
How to make this Cookie with ESP8266HTTPClient lib ?
|
@supersjimmie @Links2004
But it seems now that that referenced line is not correct anymore due to changes in the meantime. So I dont know where now to make that change... is it now line 1044? But if I change that line, it adds a semicolon to ALL header lines, corrupting i.e. the "Location" redirect URL. |
Hi, could you solve this? |
HTTPClient http;
http.begin("http://server.com/url");
code = http.POST(PostData);
Serial.printf("[HTTP] POST... code: %d\r\n", code);
res = http.getString();
Variable res now contains the webpage, but how do I read the returned headers?
(specifically the Set-Cookie?)
I have tried combinations of http.collectHeaders(), http.headers(), http.headerName(), etc...
The text was updated successfully, but these errors were encountered: