Sending a proper Post request from Arduino Mega

I am trying to send a Post request from my Arduino Mega using the Ethernet shield, I tried already many many codes all over the internet but I haven’t done yet

Also did it already from a NodeMCU-ESP8266 but I don’t know why with the mega is getting so tricky

From this code everything goes well except that I never get the POST request, I am using this website ‘requestcatcher’ to test the POST request

#include <Ethernet.h>
#include <SPI.h>

// Conf. mac 
byte mac[] = { 0xDE, 0xAD, 0xBE, 0xEF, 0xFE, 0xED };

// Server to Post
char server[] = "http://abc.requestcatcher.com/test";   

// Starting Ethernet client
EthernetClient client;

// =============== Connecting to internet =============== //

void setup() {
  // Open serial communications and wait for port to open:
  // wait for serial port to connect. Needed for native USB port only
  Serial.begin(9600);
  while (!Serial) {
    ; 
  }

  // Connecting to internet
  if (Ethernet.begin (mac) == 0) {
    Serial.println("Can’t connect via DHCP");
  }

  // Give the Ethernet shield a second to initialize
  delay(1000);
  // Printing the IP Adress
  Serial.print ("IP Address: ");
  Serial.println(Ethernet.localIP());

}

/////============= Sending Post request ============= ////

void loop() {

  Serial.println(" - Post request in process - ");

  if (client.connect(server, 80) { 
        Serial.print(" Sending Post request ");
        client.println("POST /test HTTP/1.1"); 
        client.println("Host: abc.requestcatcher.com/"); 
        client.println("Content-Type: application/x-www-form-urlencoded"); 
        client.println("Content-Length: "); 
        client.println(); 
  } 
  else {
    Serial.println("Can’t reach the server");
  }
  // Wait 10 secs
  delay(10000); 
}

Arduino prints via serial something like this

IP Adress: 192.168.100.40
- Post request in process -
Sending Post request
- Post request in process -
Sending Post request
- Post request in process -
Sending Post request

So I think that means that the Arduino connects successfully to the internet and also ‘client.connect(server, 80)’ goes true since it prints ‘Sending Post request’, but I don’t know why request catcher never gets any of the post requests, I tested ‘requestcatcher’ with online apps and as well with the NodeMCU and it gets the post request from all except the Arduino so I think something must be wrong around here:

   client.println("POST /test HTTP/1.1"); 
   client.println("Host: abc.requestcatcher.com/");        
   client.println("Content-Type: application/x-www-form-urlencoded"); 
   client.println("Content-Length: "); 
   client.println();

Please help, any hint would be very helpful

You are not sending anything in the POST request, not sending a Content-Length value, not reading the server response, nor closing the connection. Besides those you mean?

SurferTim: You are not sending anything in the POST request, not sending a Content-Length value, not reading the server response, nor closing the connection. Besides those you mean?

Thanks a lot, SurferTim, you were right I checked the protocol for the headers so here it's how finally worked

if (client.connect(server, 80)) { 
    Serial.print(" Sending Post request ");
    client.println("POST /test HTTP/1.0"); 
    client.println("Host: abc.requestcatcher.com");     
    client.println("Connection: close");
    client.println("Content-Length: 0");          //-------   I missed  0
    client.println("Content-Type: application/x-www-form-urlencoded"); 
    client.println("");                                    //-------  I missed  ""
    
    Serial.println("Server response");
    char c = client.read();
    Serial.println(c);
    client.stop();
  }

Too bad that form the server response I get "⸮" when requestcatcher actually sends "request caught"I not very sure about the lines after the http request, Could you give a little push with that?.

but also and THIS IS VERY IMPORTANT I made a mistake right on the top, I didn't know that this would count as a typo but it does the server must be written this way otherwise the server will never get the POST request

char server[] = "abc.requestcatcher.com";

Avoid setting your server like this!

char server[] ="http://abc.requestcatcher.com/test";
char server[] ="abc.requestcatcher.com/";