I'm currently using the following Arduino code on an ESP32 (I've taken out non-relevant parts) to make an https request for a binary file from a server, to store in SPIFFS. However I now need to set a custom header, and so need to use the https.beginRequest() method. But this method does not take a WiFiClientSecure reference, and so I cannot use HTTPS for this. Can the standard Arduino lib actually perform https requests with custom headers, or is there another lib for this?
WiFiClientSecure client;
client.setInsecure(); // Not using certificate check while testing
HTTPClient https;
https.useHTTP10(true);
Serial.println("https.begin...");
if (https.begin(client, "https://path.to.binary.file")) { // HTTPS
Serial.println("Sending GET request...");
//https.sendHeader("X-device: 12345678"); // Cannot use here
// start connection and send HTTP header
int httpCode=https.GET();
Serial.printf("Response code: %u\n",httpCode);
Serial.printf("Content length: %u\n",https.getSize());
uint32_t bytesRead=0;
uint8_t b;
while(client.connected()){
while(client.available()){
++bytesRead;
b=client.read();
Serial.printf("0x%02x ",b);
if((bytesRead%16)==0){
Serial.println();
}
}
}
Serial.printf("\nBytes read: %u\n",bytesRead);
https.end();
}else{
Serial.println("Could not connect to server");
}