arduino-libraries / ArduinoHttpClient

Arduino HTTP Client library
288 stars 172 forks source link

Always gets http code 400 #72

Closed neypalma closed 5 years ago

neypalma commented 5 years ago

I made a simple test program to make an http put, but the answer is always code 400

Here is the code

String contentType="application/json"; String putData="{\"sensorId\":" + String(SENSORID) + ",\"sensorValue\":34.5}"; String putPath="/v1/sensors/water/"; // put your main code here, to run repeatedly: Serial.print("Sending data "); Serial.println(putData);

httpClient.put(putPath,contentType,putData);

int httpCode=httpClient.responseStatusCode(); String httpResponse=httpClient.responseBody();

Serial.print("Http Code:"); Serial.println(httpCode); Serial.print("Http Response:"); Serial.println(httpResponse);

delay(10000);

Thanks for the help

neypalma commented 5 years ago

Well with the following code works

httpClient.beginRequest(); httpClient.put(putPath); httpClient.sendHeader("Host", "IpAddress:8085"); httpClient.sendHeader("Content-Type", "application/json"); httpClient.sendHeader("Content-Length", putData.length()); httpClient.beginBody(); httpClient.print(putData); httpClient.endRequest();