I am trying to do a HTTPS post on ESP8266 as shown in Postman below
But I keep getting: 'HTTP/1.1 401 Unauthorized'.
Can someone please help me with how to build up the headers correctly in the HTTPS POST? And maybe also give a link to some documentation? I cant seem to find any...
My code is:
const char* host = "api.dgs.com";
const int httpsPort = 443;
String url = "/ccs-int/v1/applicationdatalogging/1.0";
String msg = "";
WiFiClientSecure client;
Serial.print("connecting to : '");
Serial.print(host);
Serial.println("'");
Serial.printf("Using fingerprint '%s'\n", fingerprint);
client.setFingerprint(fingerprint);
client.connect(host, httpsPort);
Serial.print("requesting URL: '");
Serial.print(url);
Serial.println("'");
client.print(String("POST ") + url + " HTTP/1.1\r\n" +
"Host: " + host + "\r\n" +
"Connection: close\r\n" +
"Content-Type: application/json" +
"Authorization: Bearer " + authorization_code + "\r\n" +
"Content-Length: " + msg.length() + "\r\n" +
"\r\n" +
msg + "\r\n");
Serial.println("request sent");
unsigned long timeout = millis();
while (client.available() == 0) {
if (millis() - timeout > 5000) {
Serial.println(">>> Client Timeout !");
client.stop();
return;
}
}
curl -X POST --header "Authorization: Bearer AUTHCODE" --header "Content-Length: 0" https://api.dgs.com/ccs-int/v1/applicationdatalogging/1.0
replacingAUTHCODE
with your authorization code. This may help you debug what's going on with it.