Skip to content

http.getString() return blank #7692

Closed
@igorfelluga

Description

@igorfelluga

Hi
I have a simple code that read a json and display result on lcd.
After some month I resumed it but I think that some update (Arduino CLI o other) give me a problem with http.getString() that return empty string.
To do a simple test I did an empty project with only wifi connection http request.
Here my code:

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "FUNCOOL";
const char* password = "1807200505092011";


WiFiClient client;
HTTPClient http;

void setup() {

  // put your setup code here, to run once:
  Serial.begin(115200);
  WiFi.begin(ssid, password);

  while (WiFi.status() != WL_CONNECTED) {
    delay(1000);
    Serial.println("Connecting...");
  }

}

void loop() {
  if (WiFi.status() == WL_CONNECTED) {

    http.begin(client, "http://192.168.1.252/user/counter.json");
    int httpCode = http.GET();
    Serial.println("Connected");
    Serial.println(httpCode);
    //Check the returning code
    if (httpCode == 200) {
      Serial.println("Connected");
      String payload = http.getString();
      Serial.println("http string");
      Serial.println(payload);
      Serial.println("http string end");

    } else {
      Serial.println("Gateway Problem");
    }
    http.end();   //Close connection
  } else {
    Serial.println("NOT Connected! Check WiFi");
  }
  // Delay
  delay(1000);

}

when I trace it get

Connecting...
Connecting...
Connected
200
Connected
http string

http string end
Connected
200
Connected
http string

http string end
Connected
200
Connected
http string

Has you can see the payload is empty/blank.
Any suggestion for me?
Thanks

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions