Hi team, I have done some projects with Arduino but is my first with HTTP post request, so forgive me if this is a very basic issue. I have been reading a lot of stuff on the forum/internet but haven't find anything to put me on the right path and therefore any help will be greatly appreciated.
So, I have two basic issues:
First I have to post to a secure server (https://...) and according to what I have read the HTTPclient library doesn't support https. So, how to deal with this limitation?
@pylon many thanks for your prompt answer, please see remarks below
Which exact board are we talking about?
Sorry for not mentioning that in the original post. I'm using an AI-Thinker ESP32-CAM board since my end goal is to upload a picture to the service provider
This isn't complete anyway.
Not sure what is missing, as I said I'm new to this field...
You can call that method several times to add more.
Thanks for this useful hint
Post complete code!
Here it goes (already updated with two lines of headers as you explained...)
#include <WiFi.h>
#include <HTTPClient.h>
const char* ssid = "SigloXX";
const char* password = "";
void setup() {
Serial.begin(115200);
Serial.setDebugOutput(true);
Serial.println();
WiFi.begin(ssid, password);
while (WiFi.status() != WL_CONNECTED) {
delay(500);
Serial.print(".");
}
Serial.println("");
Serial.println("WiFi connected");
WiFiClient client;
HTTPClient http;
// set the server
http.begin(client, "https://mydomain.com/auth/login");
// set the headers
http.addHeader("accept", "application/json");
http.addHeader("Content-Type", "application/json");
// JSON data to send with HTTP POST
String httpRequestData = "{\"password\": \"myPassword\",\"login\": \"myLogin\"}";
// Send HTTP POST request
int httpResponseCode = http.POST(httpRequestData);
Serial.print("HTTP Response code: ");
Serial.println(httpResponseCode);
// Free resources
http.end();
}
void loop() {
}
Once again, many thanks for your willingness to help
Find out what the service you're calling expects. As you're posting only dummy data we have no clue what service you're calling.
Try first to write the Accept-Header correctly (although header fields should be case-insensitive).
@pylon again many thanks for your answer. Will try as you said. Just FYI the service I'm calling is a private service provider and therefore I can't publish the URL. I guess I'm going to ask for their support to see what is being received in the server side.