I am trying to make a POST request with NodeMCU, but I get a HTTP status code -1.


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

#ifndef STASSID
#define STASSID "Wifi" 
#define STAPSK  "123"

const char* ssid = STASSID;
const char* password = STAPSK;
const char* host = "https://laimonasjanutenas.000webhostapp.com/wifidata.php";

void setup() {
  WiFi.begin(ssid, password);
  while (WiFi.status() != WL_CONNECTED) {
  Serial.println("WiFi connected");
  Serial.println("trying to post ");

  HTTPClient http;

  http.addHeader("Content-Type", "application/x-www-form-urlencoded");

  int httpCode = http.POST("temp=1337");   

Serial monitor outputs this:

connecting to Wifi
WiFi connected
trying to post 

I can confirm that I can actually make a POST to the server. I tested in Postman using this:


I have no clue what I am doing wrong. Feel free to make POST requests to the this server if needed. Thank you.

  • what status were you expecting? .... why do you say that you are doing something wrong?
    – jsotola
    May 21 '19 at 21:37
  • 1
    Does it work if you use http instead of https? It looks like extra params are required for https: github.com/esp8266/Arduino/issues/1941 May 21 '19 at 21:50
  • 2
    Yes it works! I changed the link from https to http and it worked :). Thanks
    – katinas
    May 22 '19 at 9:13
  • 2
    To elaborate on @ChrisCombs comment, you have work to do if you want to talk HTTPS. Please read : forum.arduino.cc/index.php?topic=515541.0
    – Greycon
    Jun 18 '19 at 11:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.