Ive been trying to get POST working on my ESP8266. I followed this tutorial https://techtutorialsx.com/2016/07/21/esp8266-post-requests/ which works, but once i change the request URL to anything else i get -1 response from http.POST() which the library returns when "no info".
I have no clue what the "no info" means and what im doing wrong. Does anyone have any suggestions? Below is the code im using.
if (WiFi.status() == WL_CONNECTED) { //Check WiFi connection status
HTTPClient http; //Declare object of class HTTPClient
//http.begin("http://192.168.1.88:8085/hello"); //Works fine
//http.begin("https://httpbin.org:8080/post"); //Causes -1 as httpCode
//http.begin("https://httpbin.org/post"); //Causes -1 as httpCode
http.begin("https://XXXXX.execute-api.eu-west-2.amazonaws.com/XXXXX/XXXXX");
http.addHeader("Content-Type", "application/json"); //Specify content-type header
int httpCode = http.POST("{\"key\":\"1\",\"id\": \"ESPXXX2\",\"action\": \"rbg\",\"value\": \"255255000\"}"); //Send the request
String payload = http.getString(); //Get the response payload
Serial.println(httpCode); //Print HTTP return code
Serial.println(payload); //Print request response payload
http.end(); //Close connection
} else {
Serial.println("Error in WiFi connection");
}
delay(10000); //Send a request every 10 seconds
Only serial output im getting is "-1" for httpCode and empty line for payload.
http.begin("https://httpbin.org/post");
withhttp.POST