Get bearer token from HTTPS

Hi all

I am pretty new in the arduino world, and i have come across an issue i am unable to solve.

I need to call an api, but not just a simple http get. I need to get the bearer token from https.
I have the call working in Postman, where i pass 4 properties in the header and 2 in the body.

So far i have been googling a lot of stuff, but i have found nothing usefull.

I have tried to call the endpoint like this

#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>

const char* ssid = "ssid";
const char* password = "password";

void setup() {
Serial.begin(9600);
WiFi.begin(ssid, password);
while(WiFi.status() != WL_CONNECTED){
delay(1000);
Serial.println("Connecting...");
}
Serial.println("CONNECTED");
}

void loop() {
HTTPClient http;
String Content_Type, apikey ,identity, Fromwhere, grant_type, username, message;
Content_Type = "application/x-www-form-urlencoded";
apikey = "apikey";
identity = "identity";
Fromwhere = "application";
grant_type = "password";
username = "username";

message = "grant_type=" + grant_type + "&" + "username=" + username;

http.begin("https://MyAddress.com/token");

http.addHeader("Content-Type", Content_Type);
http.addHeader("apikey", apikey);
http.addHeader("identity", identity);
http.addHeader("Fromwhere", Fromwhere);

httpCode = http.POST(message);
String payload = http.getString();
}

but httpCode keeps comming back -1 and payload is empty.

It may just be a rookie mistake from my side, but at this point any advice would be amazing.

but httpCode keeps comming back -1 and payload is empty.

-1 means "Connection failed". So your ESP cannot create a connection to myaddress.com at port 443. Check your connectivity!

How do I test my Connectivity?

my thoughts was that my headers or body was not send currectly

How do I test my Connectivity?

Test with a local service. If that succeeds test with a service available for sure (p.e. www.google.com). If that succeeds also, your service "myaddress.com" (i hope that's a placeholder) doesn't work as expected.