arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
282 stars 170 forks source link

Headers are not being received inserver side on POST #106

Closed biswaKL closed 3 years ago

biswaKL commented 3 years ago
  TinyGsmClient client(modem);
  HttpClient http(client, server, 80);
  SerialMon.println(F("Performing HTTP POST request... "));
  String dataUpload = "asdfq123123";
  http.beginRequest();
  int err = http.post("/testing/upload", "application/json;charset=utf-8", dataUpload);
  if (err != 0)
  {
    http.stop();
    Serial.println(F("failed to connect"));
    delay(1000);
  }
  http.sendHeader("id", "asdf1234");
  http.sendHeader("File-Type", "txtfile");

  http.endRequest();

  int statusCode = http.responseStatusCode();
  String response = http.responseBody();
  http.stop();
biswaKL commented 3 years ago

Solved it, content length and content type are compulsory header. and need to use: http.post("/testing/upload");

    http.beginBody();
    http.print(data);
    http.endRequest();