HTTP Post Request(Arduino) to $_POST(PHP)

How could I get HTTP Post Request from Arduino using $_POST of PHP? or is it impossible using that method? I can't get clear tutorial or article of this thing.

Any help would greatly be appreciated.

Read up on the HTTP protocol. You just have to open a TCP socket and print HTTP text to it.
You can open the development tools in your browser to see what text is sent when you make the request from a form within the web page.

Pieter

Your question is a little confusing! You can't run PHP on an Arduino, as far as I know. So where is the PHP running and which way is the POST request going? From the Arduino to some other server, or from a server to the Arduino? The $_POST variable is an array of all the parameters passed to the PHP script by a remote client. It is not a command to initiate a POST request to a remote server.

It would help clarify things if you described what your project is about in real-world terms. Then we could make some educated guesses.

PaulRB:
Your question is a little confusing! You can't run PHP on an Arduino, as far as I know. So where is the PHP running and which way is the POST request going? From the Arduino to some other server, or from a server to the Arduino? The $_POST variable is an array of all the parameters passed to the PHP script by a remote client. It is not a command to initiate a POST request to a remote server.

It would help clarify things if you described what your project is about in real-world terms. Then we could make some educated guesses.

I want my Arduino to sent HTTP POST Request to the server and I am new to this stuff so I don't know basics of it. I want the server to get the data and save it into my database. Any clues and references?

  • Can PHP get that request on the server side?
  • Do I have to open the browser all the time to make my PHP run?

OninVR:

  • Can PHP get that request on the server side?

Yes.

OninVR:

  • Do I have to open the browser all the time to make my PHP run?

No, the browser is just a client, just like the Arduino is just a client. The server is a separate application, it doesn't require nor imply the use of a browser.

Pieter

have a look at the sensors I built here.

void httpRequest(String data)
{
  String request = "GET /sen_track/get.php?data=";
  request += data;
  request += " HTTP/1.1\r\nHost: 192.168.43.171 : 8080\r\nAccept: */*\r\nContent-Length: ";
  request += data.length();
  request +="\r\nContent-type: text/html\r\nConnection: close\r\n";
  Serial.println(request);
  espSerial();
  esp.print("AT+CIPSEND=");
  esp.println(request.length());
  delay(500);
  if(esp.find("OK"))
  {
    Serial.print("Sending");
    espSerial();
    esp.print(request);
    delay(200);
  }
  if( esp.find("SEND OK"))
  {
    Serial.println();
    Serial.println("Packet sent");
    if(esp.find("400"))
      Serial.println("Bad Request");
  }

  esp.println("AT+CIPCLOSE");
  espSerial();
}

I always get HTTP 1.1/ 400 Bad request.

Is there something wrong with my HTTP request? Help please.

do not add port to Host header, only the IP address remove the spaces around : in Host header and add an empty line after the last header.

remove the Content-lenght header if you have a GET request

Juraj:
do not add port to Host header, only the IP address

Why not?

PieterP:
Why not?

RFC 7230 - Hypertext Transfer Protocol (HTTP/1.1): Message Syntax and Routing

Sir PieterP,

What do you think are my mistakes?

OninVR:
Sir PieterP,

What do you think are my mistakes?

It was my mistake, in my comment. read it