I have a ESP-S3 board and am trying to get JSON data from our server. I am using the following code (see below) as a basis for mine.
This code works. If I change
http://jsonplaceholder.typicode.com/comments?id=10
I do get the html for our server's main page.
If I then change
http://mywebsite.com
to
http://mywebsite.com/profiles
I get status code 200 but no JSON.
I type http://mywebsite.com/profiles in a browser it returns the JSON or if I use postman and do a GET on http://mywebsite.com/profiles it returns JSON.
It sounds like this issue posted a couple of years ago: esp32 http client response only 200 didn't receive the data after that
Any insight as to what I am doing wrong would be greatly appreciated.
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "yourNetworkName";
const char* password = "yourPassword";
void setup() {
Serial.begin(115200);
delay(4000);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(1000);
Serial.println("Connecting to WiFi..");
}
Serial.println("Connected to the WiFi network");
}
void loop() {
if ((WiFi.status() == WL_CONNECTED)) { //Check the current connection status
HTTPClient http;
http.begin("http://jsonplaceholder.typicode.com/comments?id=10"); //Specify the URL
int httpCode = http.GET(); //Make the request
if (httpCode > 0) { //Check for the returning code
String payload = http.getString();
Serial.println(httpCode);
Serial.println(payload);
}
else {
Serial.println("Error on HTTP request");
}
http.end(); //Free the resources
}
delay(10000);
}
String payload = http.getString();
andSerial.println(httpCode);
, this might provided sufficient time for payload to be received completely.