-->
Page 1 of 2

Unable to access HTTPS URL JSON data

PostPosted: Sun Mar 10, 2019 11:51 am
by sadiq1aziz
Hi there

I need help urgently.

I tried to access JSON text on a HTTPS URL. Can't do so on HTTP. I used the template code in the examples section of the Arduino IDE file tab (ESP8266WiFi- HTTPSREQUEST).
i use client.readStringUntil(\n); to read the text.

After execution, it takes a while to get the text response. And when i do, part of the JSON text gets printed in the Serial monitor, followed quite shortly by a soft WDT reset.

I get some stack dump, and then it hangs...

Here is the header i get

X-Authentication-Time: 1ms
Cache-Control: max-age=60
Expires: Sun, 10 Mar 2019 12:53:54 +0000
X-Content-Type-Options: nosniff
X-Response-Time: 141.798ms
Vary: Accept-Encoding

If anyone has a proper functional template to read JSON text from a HTTPS URL via GET request , please post it below. I'd greatly appreciate your help!

Re: Unable to access HTTPS URL JSON data

PostPosted: Sun Mar 10, 2019 7:23 pm
by RichardS
Seen this happen where the response is too long and it will not print correctly...

take the response and in a loop print out one character at a time to make sure...

char *p = response;
while(*p) {
Serial.print(*p++);
delay(0);
}

Re: Unable to access HTTPS URL JSON data

PostPosted: Mon Mar 11, 2019 12:27 am
by sadiq1aziz
RichardS wrote:Seen this happen where the response is too long and it will not print correctly...

take the response and in a loop print out one character at a time to make sure...

char *p = response;
while(*p) {
Serial.print(*p++);
delay(0);
}



You're right!

I fiddled about the code for a while after making this post and then decided to use a while loop with a break statement to execute the function to read string. Turns out it worked! It then dawned on me that the JSON data had to be read a character at a time to ensure that only the intended part of the JSON text and not the whole data dump was read until the terminating character. What happened earlier was that the "readStringUntil" function would overshoot the terminating character, attempt to read the whole JSON text only to hang with a WDTsoft reset. Glad to be rid of this problem!

Many thanks for your suggestion :)

Re: Unable to access HTTPS URL JSON data

PostPosted: Mon Mar 11, 2019 9:41 am
by sadiq1aziz
Hey thanks for the suggestion! I tier out something similar, and it kind of solved one part of my problem :). I've posted another query related to that. If possible could you take a look?