title: POST request with ESP32 returns 301
body: <p>I have a NGINX server on a raspberry pi. I want to send JSON file from my ESP32 board to the NGINX web-server.</p>
  
  <p>In a first step, I have followed this tutorial : 
  <a href="https://techtutorialsx.com/2017/05/20/esp32-http-post-requests/" rel="nofollow noreferrer">https://techtutorialsx.com/2017/05/20/esp32-http-post-requests/</a></p>
  
  <p>It gives this code : </p>
  
  <pre><code>#include &lt;WiFi.h&gt;
  #include &lt;HTTPClient.h&gt;
  
  const char* ssid = "yourNetworkName";
  const char* password =  "yourNetworkPassword";
  
  void setup() {
  
    Serial.begin(115200);
    delay(4000);   //Delay needed before calling the WiFi.begin
  
    WiFi.begin(ssid, password); 
  
    while (WiFi.status() != WL_CONNECTED) { //Check for the connection
      delay(1000);
      Serial.println("Connecting to WiFi..");
    }
  
    Serial.println("Connected to the WiFi network");
  
  }
  
  void loop() {
  
   if(WiFi.status()== WL_CONNECTED){   //Check WiFi connection status
  
     HTTPClient http;   
  
     http.begin("http://jsonplaceholder.typicode.com/posts");  //Specify destination for HTTP request
     http.addHeader("Content-Type", "text/plain");             //Specify content-type header
  
     int httpResponseCode = http.POST("POSTING from ESP32");   //Send the actual POST request
  
     if(httpResponseCode&gt;0){
  
      String response = http.getString();                       //Get the response to the request
  
      Serial.println(httpResponseCode);   //Print return code
      Serial.println(response);           //Print request answer
  
     }else{
  
      Serial.print("Error on sending POST: ");
      Serial.println(httpResponseCode);
  
     }
  
     http.end();  //Free resources
  
   }else{
  
      Serial.println("Error in WiFi connection");   
  
   }
  
    delay(10000);  //Send a request every 10 seconds
  
  }
  </code></pre>
  
  <p>No problem if I use this code with the following line </p>
  
  <pre><code>http.begin("http://jsonplaceholder.typicode.com/posts");
  </code></pre>
  
  <p>My serial monitor of the ARDUINO's IDE returns : </p>
  
  <pre><code>201
  {
    "id": 101
  }
  </code></pre>
  
  <p>But, when I only replace the previous line by</p>
  
  <pre><code>http.begin("http://82.145.56.62:151/postfile");
  </code></pre>
  
  <p>I get on my serial monitor this : </p>
  
  <pre><code>301
  &lt;html&gt;
  &lt;head&gt;&lt;title&gt;301 Moved Permanently&lt;/title&gt;&lt;/head&gt;
  &lt;body bgcolor="white"&gt;
  &lt;center&gt;&lt;h1&gt;301 Moved Permanently&lt;/h1&gt;&lt;/center&gt;
  &lt;hr&gt;&lt;center&gt;nginx/1.10.3&lt;/center&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>Would you have an idea of my problem ?</p>
  
  <p>Thank you ,</p>
  
  <p><strong>EDIT</strong></p>
  
  <p>I have gone ahead a little more. I have created a php file in the directory <strong>posts</strong>. Now I get the HTTP code 200, so my webserver receive the POST request.</p>
  
  <p><strong>New problem :</strong> I cannot figure out how to display the POST content on my php file. Would you have an idea ?</p>
  
  <p>Thank you,</p>