Hi!
Im trying to communicate with a API through an ESP8266 and im having some troubles.
I am able to connect and parse the data from http://jsonplaceholder.typicode.com/users/1 using ArduinoJson Version 6 without any issues.
Im not able to authenticate myself against the API and get a "max int" return when i try to check the http code.
API Instructions:
HTTP POST or HTTP Basic Auth needs to be used to get the data.
Im trying to use HTTP Basic Auth.
"For HTTP Basic Auth you have to add the Authorization header with the request. The Authorization header is constructed as follows:"
Username and password are combined into a string username:password or if you use the api token it should be combined xxxx:api_token (xxx indicating user's personal token)
The resulting string literal is then encoded using Base64
The authorization method and a space i.e. "Basic " is then put before the encoded string.
For example, if the user agent uses 'Aladdin' as the username and 'open sesame' as the password then the header is formed as follows: Authorization: Basic QWxhZGRpbjpvcGVuIHNlc2FtZQ==
curl -u xxxx:api_token -X GET XXX Sex - Free Porn Videos at XXX.com
This is the part of my code that im using to create the request. I am able to make the request using curl in CMD.
//Used packages
#include <ArduinoJson.h>
#include <ESP8266WiFi.h>
#include <ESP8266HTTPClient.h>
uint16_t httpCode{};
HTTPClient http;
WiFi.begin(user, pass);
http.begin("URL");
http.addHeader("Authorization:", "Basic MyTokenInBase64", true);
httpCode = http.GET();
//Further down in code
deserializeJson(doc, http.getString(), DeserializationOption::Filter(filter));
I have tried to not Base64 encode the token and get the same problem. Ive also tried to use the ".setAuthorization(Basic MyTokenInBase64);" but it doesn't work.
I would appreciate any help since im new to HTTP requests.
Also as a side note, whats does the boolean do in the "addHeader" function. The reference isn't really helpful in this case. void HTTPClient::addHeader ( const String & name, const String & value, bool first = false )