Closed Nocturnalecode closed 4 years ago
I have figured that occurs on my office's internet connection but works good at home and figured something that json comes like this at home;
22:33:31.234 ->{"transmitterHost":"","pairingCode":"2366dfe831104da0aff6bb9769074fa8"}
but at office it comes like;
09:59:37.230 -> 47 09:59:37.230 -> {"transmitterHost":"","pairingCode":"2366dfe831104da0aff6bb9769074fa8"} 09:59:37.230 -> 0 09:59:37.230 -> 09:59:37.230 ->
have 47 before object, 0 and two whitespace after object. is there a way to ignore those characters and just start from "{" and end at "}" ?
@Nocturnalecode,
that is a HTTP 1.1 chunked response. The 47 means that the next chunk contains 47 bytes, and the 0 means "end of transmit".
But according to the ESP Arduino source code (from your code I assumed you are working with ESP 8266/32) on my system both HTTPClient::getString() and HTTPClient::writeToStream() should be able to recognize and handle these.
However it may be possible that I fixed a defect in the ESP Arduino HTTPClient library and forget to post a PR. Will go back and check and compare my version with the latest master.
Are you using the master branch on GitHub or a specific version? Ewald
@ewaldc i am an alien for github actually trying to get used to. By changing connection it works well, not sure why that occurs on office's connection. Http getstring takes too long to get a response in office also. Might be rooter or service provider. Don't know.
Hi @Nocturnalecode,
I agree with @ewaldc, ESP8266HTTPClient should handle chunked transfer encoding for you. I don't know why it doesn't work; you should ask the authors of the library.
By the way, I see that your program is duplicating the response several times. Please read How to use ArduinoJson with ESP8266HTTPClient? to learn how to improve your program.
Best regards, Benoit
Hi @Nocturnalecode,
It just came to my attention that ESP8266HTTPClient doesn't handle chunked transfer encoding when we use getStream()
, so you must call useHTTP10(true)
before sending the request.
I updated the documentation accordingly.
Best regards, Benoit
@bblanchon @ewaldc thanks for help guys.
You're welcome @Nocturnalecode. Thank you for using ArduinoJson.
Hello, i recieve "Invalid Input" error always Can you check my code if anything wrong? Trying to debug it with prints but returning json seems correct and looks like this:
When i print payload to serial port screen i see this line:
{"transmitterHost":"ESP_0EC076","pairingCode":"625006a517cc4eb9b57d95a9654ba5e7"}
But parsing fails.Also it's takes so long to get jsonstring (about 40 seconds). Using ESP8266HTTPClient library for that. If problem is that, have any advice for getting json? or if anythn else, have any idea?