I have found this header only library called cpp-httplib, which seems to work fine for my purposes. I need to control a camera through HTTP requests. For example, I can read the current position of the camera using:
httplib::Client cli("192.170.0.201", 8080);
auto res = cli.Get("/ptz.stats/present_pos");
which corresponds to the following Curl command;
curl -X GET "http://192.170.0.201:8080/ptz.stats/present_pos"
Now, I want to move the camera using a POST request. With curl, I can use following command to move the camera to left:
curl -X POST "http://192.170.0.201:8080/ptz.cmd/?pan_left=50"
I want to make the exact same POST request from httplib
using
httplib::Client cli("192.170.0.201", 8080);
httplib::Params params{
{ "pan_left", "50" }
};
auto p = cli.Post("/ptz.cmd", params);
and this does nothing. I can see the camera and that curl command moves it. So, am I translating the POST request to httplib
format in a wrong way? How would you call that curl request in httplib
?
PS: httplib
might not be a popular library but it has neat documentation and I think anyone working with web requests and C++ can help.
Related question: How are parameters sent in an HTTP POST request?
POST parameters are not sent in the URI. From the cpp-httplib github, you can sent url-encoded parameters using:
cli.Post("/ptz.cmd", "pan_left=50", "application/x-www-form-urlencoded");
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With