csquared / arduino-restclient

Arduino RESTful HTTP Request Library
MIT License
205 stars 133 forks source link

Fixed Requests! #10

Open CyborgHead opened 8 years ago

CyborgHead commented 8 years ago

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);

sbonkosky commented 8 years ago

@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);