post with variable values
mateusguilhermedasilva opened this issue · 1 comments
mateusguilhermedasilva commented
Hello
how to send a post using values from a variable?
for example:
client.postAsync("https://httpbin.org/post", "{"sensor": ""+(String)valueOfSensor+""}");
thanks
imrehorvath commented
Hello,
For a simple case you can try the following:
String data = "{\"sensorValue\":\"";
data += valueOfSensor;
data += "\"}";
client.postAsync("https://httpbin.org/post", data.c_str());
However if your data is more complex, you can try using the ArduinoJson library to serialize your JSON document.
Please note as of v3.2.0, you can use String
in the API. So, you may omit the .c_str()
, eg.:
String data = "{\"sensorValue\":\"";
data += valueOfSensor;
data += "\"}";
client.postAsync("https://httpbin.org/post", data);