3

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.

meguli
  • 1,156
  • 13
  • 25
  • 1
    Shouldn't this be { "?pan_left", "50" }? – Beginner Sep 11 '18 at 11:38
  • I thought "?" would be added automatically but anyways, tried adding it as well. It does not work that way either. I know it is impossible for others to test since I have a physical camera. Still, it is more about HTTP parameters than the camera itself. – meguli Sep 11 '18 at 11:52

1 Answers1

3

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");
BenMercs
  • 31
  • 3