arduino-restclient icon indicating copy to clipboard operation
arduino-restclient copied to clipboard

Fixed Requests!

Open CyborgHead opened this issue 10 years ago • 1 comments
trafficstars

How is it possible to make dynamic requests using this library?

The following code snippets will NOT work since you made the URL of the GET Request and the Body of the POST Requests Constant.

// GET Request. int statusCode = client.get("/api/myservice/id=" + id, &response);

// POST Request. char postdata = /* Some data from function parameter, for example. */; int statusCode = client.post(""/api/myservice/id", postdata , &response);

CyborgHead avatar Nov 21 '15 17:11 CyborgHead

@CyborgHead Build your request in a String object and then use .c_str() to convert to a const char*, like so:

String data = "/api/myservice/id=" + id; int statusCode = client.post("/api/myservice/id", data.c_str() , &response);

sbonkosky avatar Apr 18 '16 00:04 sbonkosky