title: Sending an HTTP Post Request with ESP8266
body: <p>I am trying to make a POST request using my esp8266. I have set up a webhook and I am trying to call it using my esp8266. I have tried various methods but it doesn't seem to work. </p>
  
  <p>I first tried to use the ESP8266HTTPClient Library but it didn't work.
  I then tried to directly make the post request through the 'client.println' but it also didn't work. When I figured out that I can't send http requests to the webhook I set up, I started sending it to a local website that I made through express so it would be easier to test it. When sending a simple curl command I get the right response however when I try to send the http call through the esp8266 I can't.</p>
  
  <p>Here is my attempt using the ESP8266HTTPClient library: </p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;WiFiClient.h&gt; 
  #include &lt;ESP8266WebServer.h&gt;
  #include &lt;ESP8266HTTPClient.h&gt;
  
  const int sensorPin = 4;
  
  WiFiServer server(80);
  
  const  String altLink = "http://localhost:3000/message";
  
  const String ssid = "shefer 2.4GHz";
  const String password = "1234554321";
  
  void setup() {
    Serial.begin(9600);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid,password);
  
    while(WiFi.status() != WL_CONNECTED){
      delay(500);
      Serial.print(".");
    }
  
    Serial.println();
    Serial.print("Connected, IP Address: ");
    Serial.println(WiFi.localIP());
    server.begin();
  }
  
  void loop() {
    HTTPClient http;
    http.begin(altLink);
    http.addHeader("Content-Type", "text/plain");
    int sensorValue = int(analogRead(sensorPin)/128);
    if(sensorValue &gt;= 0 &amp;&amp; sensorValue &lt;=3){
      Serial.println("Light is on, sending request");
      int httpCode = http.POST("Hello from esp8266");
      //int httpCode = http.POST("");
      Serial.println("HTTP Code: " + httpCode);
      if (httpCode != 200){
        Serial.println("Couldn't send the request, got code: " + httpCode);
      } else {
        Serial.println("Request was sent successfully");
      }
      http.end();
      delay(5000);
    }
   }
  </code></pre>
  
  <p>And here is my attempt directly making the post request through 'client.println'</p>
  
  <pre><code>#include &lt;ESP8266WiFi.h&gt;
  #include &lt;WiFiClient.h&gt; 
  #include &lt;ESP8266WebServer.h&gt;
  
  WiFiServer server(80);
  
  const String ssid = "shefer 2.4GHz";
  const String password = "1234554321";
  
  void setup() {
    Serial.begin(9600);
    Serial.print("Connecting to ");
    Serial.println(ssid);
    WiFi.begin(ssid,password);
  
    while(WiFi.status() != WL_CONNECTED){
      delay(500);
      Serial.print(".");
    }
  
    Serial.println();
    Serial.print("Connected, IP Address: ");
    Serial.println(WiFi.localIP());
    server.begin();
  }
  
  void loop() {
    WiFiClient client;
    String data;
    Serial.print("Requesting POST: ");
     // Send request to the server:
     client.println("POST /message HTTP/1.1");
     client.println("Host: localhost:3000");
     client.println("Accept: */*");
     client.println("Content-Type: text/plain");
     client.print("Content-Length: ");
     client.println(data.length());
     client.println();
     client.print(data);
     delay(50000);
   }
  </code></pre>
  
  <p>I expect the esp8266 to send a POST request but it doesn't. I have tried many things and I am pretty desperate. All help would be greatly appreciated. Thank you.</p>