0

For a school projecht we want to read data from the data pins and send them to a php aplication. We get the data and can make a json string from it, but when we try to send the data (multidimensional) the $_POST var is empty of the php script (it returns the $_POST var).

Do we something wrong? we can not find a working example.

Thanks.

Sending part:

Serial.println("versturen...");           

String postData = "{\"naam\":\"ik\"}";
/*apiconnectie.beginRequest();
apiconnectie.post(path);
//apiconnectie.sendHeader("Content-Type", "application/x-www-form-urlencoded");
apiconnectie.sendHeader("Content-Type", "application/json");
apiconnectie.sendHeader("Content-Length", postData.length());
apiconnectie.beginBody();
apiconnectie.print(postData);
apiconnectie.endRequest(); */

apiconnectie.beginRequest();
apiconnectie.post(path);
apiconnectie.print("Content-Length: ");
apiconnectie.println(postData.length());
apiconnectie.println();
apiconnectie.println(postData);


statusCode = apiconnectie.responseStatusCode();
response = apiconnectie.responseBody();

Serial.println("Status code: ");
Serial.println(statusCode);
Serial.println("Response: ");
Serial.println(response);
user3142817
  • 787
  • 2
  • 9
  • 15
  • Also asked at https://forum.arduino.cc/index.php?topic=661799.0 – hcheung Jan 30 '20 at 13:02
  • You tagged `ArduinoJson`, but the code doesn't resemble anything about ArduinoJson framework, maybe you need to provide more explanation on your setup and what kind of the library you are using, the code you posted so far is insufficient to know what's going on? – hcheung Jan 30 '20 at 13:05
  • Also have you test your PHP server that it is able to receive post request correctly by using some tool such as [postman](https://www.getpostman.com)? – hcheung Jan 30 '20 at 13:06

0 Answers0