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.