I'm recently working on an Arduino project that requires using HTTP requests.
The following is my code
sender.begin(dataServer);
sender.addHeader("Content-Type", "application/json; charset=UTF-8");
while (true) {
if (sendSignal) {
sendData["id"] = StationID;
Serial.println("sending");
String sendString;
serializeJson(sendData, sendString);
Serial.println(sendString);
int code = sender.POST(sendString);
sender.end(); // AI suggests to put it in
Serial.println(code);
sendSignal = false;
blinkState = !blinkState;
digitalWrite(LED_BUILTIN, blinkState);
}
The problem was: everytime, the request after a 200 ok
request always shows -2
(HTTPC_ERROR_SEND_HEADER_FAILED
)
I tried asking AI but none of their suggestions worked.
I hope that there's no failure sending the request.
Can anyone help with this problem? Thanks.