POST command from Web client not working

Hi, I am having problems trying to send data from my arduino to a server in php.

Here is the main code in arduino

String data ="name=45678";

  // if you get a connection, report back via serial:
  if (client.connect(server, 80)) {
    Serial.print("connected to ");
    Serial.println(client.remoteIP());
    // Make a HTTP request:
   // client.println("POST /arduino_server_doble.php HTTP/1.1");
    client.println("POST /recepcion_sencilla.php HTTP/1.1");
    client.println("Host: www.ploric.online\r\nConnection: close\r\n");
    client.println("Content-Type: application/x-www-form-urlencoded;"); 
    client.println("Content-Length: ");
    client.println(data.length());
    client.println();
    
    client.println(data);
 //   client.println("Connection: close");
    client.println();
  } else {
    // if you didn't get a connection to the server:
    Serial.println("connection failed");
  }
  beginMicros = micros();
}

void loop() {

  if(client.available())
  {
    char c = client.read();
    Serial.print(c); //echo all data received
  }

 // delay(5000);
  if (!client.connected())
  {
    Serial.println();
    Serial.println("disconnecting");
    client.stop();
    for (;;)
    ;
  }
}

And here is the reponse I am getting from the server

Initialize Ethernet with DHCP:
  DHCP assigned IP 192.168.1.39
connecting to www.ploric.online...
connected to 198.23.57.183
HTTP/1.1 200 OK
Date: Sun, 10 May 2020 11:42:33 GMT
Server: Apache
X-Powered-By: PHP/7.3.17
Vary: Accept-Encoding,User-Agent
Connection: close
Transfer-Encoding: chunked
Content-Type: text/html; charset=UTF-8

8b
<html>
<head>
  <title>recepcion_sencilla.php</title>
</head>
<body>
  Name is empty
New record created successfully	
  </body>
</html>

0


disconnecting

So the problem I am having is that in the server side I can’t read the variable, it is empty.

This is the server code

if ($_SERVER["REQUEST_METHOD"] == "POST")
  {
    // collect value of input field
   $name = $_POST["name"];
 
   if (empty($name)) {
        echo "Name is empty";}

I would appreciate your comments

Best Regards

Jose

client.print("Content-Length: ");

You mean client.print("Content-Length: "); instead of client.println("Content-Length: ");?

I did that but the result is the same. "Name is empty"

jialarcon:
You mean client.print("Content-Length: "); instead of client.println("Content-Length: ");?

I did that but the result is the same. "Name is empty"

it was not a suggestion, idea or something to try. it must be so. it is a protocol not a fairy tail

Ok thanks, I did that but there must be something else because the problem remains.

Hi, in case anyone is interested it finally worked removing the Connection: close stament of the header.

Regards

jialarcon:
Hi, in case anyone is interested it finally worked removing the Connection: close stament of the header.

Regards

now I see it. there is an empty line created with \r\n and println. so 'print' without 'ln' or remove \r\n at the end of the string

Thanks, what I finally did to show it clear was

client.println("Host: www.ploric.online");
client.println("Connection: close");

And that way it works great,

Regards