I am trying to make a POST request with NodeMCU, but I get a HTTP status code -1.
Code:
#include <ESP8266HTTPClient.h>
#include <ESP8266WiFi.h>
#ifndef STASSID
#define STASSID "Wifi"
#define STAPSK "123"
#endif
const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "https://laimonasjanutenas.000webhostapp.com/wifidata.php";
void setup() {
Serial.begin(115200);
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("WiFi connected");
Serial.println("trying to post ");
HTTPClient http;
http.begin(host);
http.addHeader("Content-Type", "application/x-www-form-urlencoded");
int httpCode = http.POST("temp=1337");
Serial.println(httpCode);
http.end();
}
Serial monitor outputs this:
connecting to Wifi
........
WiFi connected
trying to post
-1
I can confirm that I can actually make a POST to the server. I tested in Postman using this:
https://laimonasjanutenas.000webhostapp.com/wifidata.php?temp=159
I have no clue what I am doing wrong. Feel free to make POST requests to the this server if needed. Thank you.