Hello,
I have the following code to post some data to a webserver. I adjusted one of the templates available:
void log_data (String datum, String uhrzeit, String kartentyp, String kartennummer, String zutritt_erlaubt)
{
HTTPClient http;
//Build call string:
String dataline = "https://<myurl>/log_data.php";
dataline += "?datum=" + datum;
dataline += "&uhrzeit=" + uhrzeit;
dataline += "&kartentyp=" + kartentyp;
dataline += "&kartennummer=" + kartennummer;
dataline += "&zutritt_erlaubt=" + zutritt_erlaubt;
bool httpResult = http.begin(dataline);
if(!httpResult)
{
Serial.println(F("[FEHLER]: Invalid HTTP request:"));
Serial.println(dataline);
}
else
{
int httpCode = http.GET();
if (httpCode > 0) { // Request has been made
Serial.printf("[INFO]: HTTP status: %d\n", httpCode);
String payload = http.getString();
Serial.println(payload);
}
else
{ // Request could not be made
Serial.printf("[FEHLER]: GET... fehlgeschlagen, Fehler: %s\n", http.errorToString(httpCode).c_str());
}
}
http.end();
}
The problem is: The URL which is being generated ("dataline") works perfectly when I paste it into the address line of my browser. But the Arduino always ends up with "Invalid HTTP request" - and I have no idea why. And since I only get a bool as return value, I don't have any idea where to keep looking at.
Is it because I'm posting towards a HTTPS site?
Any help is appreciated - thanks (spent at least four hours now without any succes)