Sending HTTP Request from ESP async server endpoint

Hi :slight_smile:

I created a small web application on my ESP8266 with a menu to do some initial settings like wifi credentials.
Now, I would like to connect the device to a web backend. So there is a REST API running that is reachable over the internet.

I would like to enter a token in the device web ui that sends a request to its backend that sends a POST request to the REST API, get's the response and returns this to the UI again.

My code looks like that (I broke it down to the very basics):

void handleRequest(AsyncWebServerRequest *request) {
    HTTPClient http;
    WiFiClientSecure wifiClient;
    wifiClient.setInsecure();
    
    String url = "https://my-backend.com";
    http.begin(wifiClient, url);
    
    int httpCode = http.GET();
    String payload = http.getString();
    Serial.println(payload);
    Serial.println(httpCode);
}

and 

server.on("/register", HTTP_GET, handleRequest)

The code snippet does work when I build it into a function that is called in the setup() or loop() and returns a 200. However, when I call /register on the esp the function is triggered, but the status code is -1 and I don't get any payload.
I am wondering if it is because of the asynchronous way the method is executed...

What can I do to communicate to the backend from my configuration interface and doing some processing in the ESP-backend on the way?

Your post is confusing... Im struggling to understand what is trying to talk to what...

The device is the ESP8266 ?

Maybe a picture would help...

This topic was automatically closed 180 days after the last reply. New replies are no longer allowed.