0

We are trying to make an HTTPS POST request from ESP8266 to aws cloud but unable to communicate to the server. The code snippet is given below:

WiFiClientSecure client;
char data[100];
DynamicJsonBuffer jsonBuffer;
char host[] = "test.execute-api.us-east-1.amazonaws.com";
if (client.connect(host, 443)) {
   String URL = "/dev";
   JsonObject& root = jsonBuffer.createObject();
   root["Id"] = 105132;
   sprintf(data, "{\"Id\":105132}");
   client.println("POST " + URL+ " HTTP/1.1");
   client.print("Host: " + (String)host);  
   client.println("User-Agent: arduino/1.0");
   client.println(data);
   client.println("Content-Type: application/json");
}

The working postman request given below:

URL : https://test.execute-api.us-east-1.amazonaws.com/dev 
Header : Content-Type : application/json
Body : {"Id" : 105132 }
Süresh AK
  • 344
  • 3
  • 20
  • 1
    you have a HTTP header after the request body and the empty line separating the headers from request body is missing. and Content-length header should be set for POST request – Juraj Mar 08 '20 at 09:52
  • Is that enough for making an HTTPS request? – Süresh AK Mar 08 '20 at 13:22
  • Your code does not show that you've setup the fingerprint for the SSL cert. See [this](https://github.com/esp8266/Arduino/blob/master/libraries/ESP8266WiFi/examples/HTTPSRequest/HTTPSRequest.ino#L58) example for the implementation. – hcheung Mar 11 '20 at 06:15

0 Answers0