HTTPS POST method in esp32 (Getting Server response 400).

I was trying to connect with my server. But, I was unable to post the data. The server is HTTPS.

* set SSL/TLS certificate */
    client.setCACert(ca_cert);
//////////////////////////////// try to connect to server again and POST the data on the cloud //////////////////////////
  if (!client.connect(host, httpsPort)) 
  {
   Serial.println("Connection failed!");
    } else {
        Serial.println("Connected to server!");
    
   client.println("POST /devices/deviceData HTTP/1.1");
  client.println("Host: api.thi***i.io");
  client.println("cache-control: no-cache");
  client.println("Content-Type: application/json");
  client.println("Authorization: Bearer eyJ0e***");
  client.println("Postman-Token: b1f4e147-8d13-4a27-a1a9-b****");
  client.println();
  client.print("Content-Length: ");
  client.println(PostValue.length());
  client.println();
  client.println(PostValue);
    }
//////////////////////////////////POSTING the data on to the cloud is done and now get the response form cloud server//////////////////
 Serial.print("Waiting for response ");
  while (client.available() == 0) 
  {
    if (millis() - timeout > 50000) 
    {
      Serial.println(">>> Client Timeout !");
      client.stop();
      return;
    }
  }
  
  Serial.println("Response From Server");
  while(client.available())
  { 
    char c = client.read();
            Serial.write(c);
    
  }

Can I know, why I am getting server response 400 again and again?

remove the empty line before the content-length header

Hi,

Thanks for reply.
I have removed the empty line above Content-Length. But, still i am getting the same issue. I am trying to use HTTPS POST.
The error is "HTTP/1.1 400 Bad Request".
Please check it.

Thanks.

Is anyone there?
:confused: :confused:

Try it first with GET method, I can help you if you want.
E-mail me: martinius96@gmail.com