You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I finally got header fetch working. I find a problem with it.
Firstly, this feature should have an example. I can provide one since I finally got it working on my fourth attempt.
Second:
One has to know the name of the header(s) and list them in the C code to be able to get them.
The http.headers() call does not report the actual number of headers in the returned data, it simply reports the number of names you entered into the headerKeys array. I already know that number, I had to enter them. It should return the number of headers that are available so they can be iterated through.
The author uses size_t and the current Arduino compiler release has a problem with that definition. I forgot the error message but it is repeatable, for the most part. Sometimes it care, sometimes it does not care. It would be easier on us programmers if you used a long integer or even just integer. There will not be over 2 billion headers in one file. size_t is surely overkill and an obscure variable type that confuses the compiler.
headerKeysCount already has the same number that http.headers() returns. Redundant and, therefore, useless. This needs correction to return the actual count of found headers. In the data I receive, there are 4 headers but .headers returns 1 because I listed only 1 in the array.
Let Firefox be your guide. It shows all four returned headers. That's how I verified they are there and verified the name of the header I needed.
Here is the code I ended up with (after 3 wrong/incomplete AI responses and then more in-depth digging through web pages):
const char *headerKeys[] = {"x-ratelimit-remaining-month"}; // The only header I care about.
const size_t headerKeysCount = sizeof(headerKeys) / sizeof(headerKeys[0]); // Returns 1
http.collectHeaders(headerKeys, headerKeysCount);
if (iHttpResponseCode == 200) { // 200 is goodness!
// Print all headers
int headerCount = http.headers(); // Simply a count of elements of the headerKeys array. Returns 1
// Serial.printf("\r\n%i HTTP header(s) sought:\r\n", headerCount);
for (int i = 0; i < headerCount; i++) {
// Serial.println(http.header((size_t) 0)); // size_t is required to be coded!
sTemp = http.header((size_t) 0); // size_t is required to be coded!
sTemp = sTemp.substring(0, sTemp.lastIndexOf(":"));
// Serial.printf("%s: %s gave %s\r\n",
// http.headerName(i).c_str(),
// http.header(i).c_str(), sTemp);
Serial.printf("There are %s /*%i*/ XRate calls left for this key"
" this month.\r\n", sTemp/*, sTemp.toInt()*/);
}
Describe the solution you'd like
See above.
Return all headers you find.
Return the count of all headers you find for iteration through them.
Don't require the user to specify the header name in advance. Collect all of them.
Create a working example. (I have one if you want to start from there)
Describe alternatives you've considered
None. There are no alternatives. I use HTTPClient.
Additional context
No response
I have checked existing list of Feature requests and the Contribution Guide
I confirm I have checked existing list of Feature requests and Contribution Guide.
The text was updated successfully, but these errors were encountered:
we do not collect all headers on purpose. They do take quite a bit of memory in many cases. We could look into a way to say specifically to collect them all. Would that work for you?
Related area
WiFi
Hardware specification
ESP32
Is your feature request related to a problem?
I finally got header fetch working. I find a problem with it.
Firstly, this feature should have an example. I can provide one since I finally got it working on my fourth attempt.
Second:
Here is the code I ended up with (after 3 wrong/incomplete AI responses and then more in-depth digging through web pages):
Describe the solution you'd like
See above.
Return all headers you find.
Return the count of all headers you find for iteration through them.
Don't require the user to specify the header name in advance. Collect all of them.
Create a working example. (I have one if you want to start from there)
Describe alternatives you've considered
None. There are no alternatives. I use HTTPClient.
Additional context
No response
I have checked existing list of Feature requests and the Contribution Guide
The text was updated successfully, but these errors were encountered: