0

I am looking for a way to use and create simple HTTP PUT requests in C++11 in the form of x-www-form-urlencoded my project is built without CMake however, so I cannot use libraries such as cpr. I have looked into curl and libcurl but they seem far too complicated and hard to implement in Windows, and in Visual Studio 2019.

I have also viewed previously asked questions such as this but it's over 10 years old and I was hoping better and more efficient methods would be available.

My friend recommends using Boost.Asio however, again it seems overly complicated.

edit: I can use libraries, just not ones that require CMake. As my project is built without CMake and creating it again would be tedious and would take a long time.

edit2: I managed to solve my issue using this library. This library seemed to be the easiest to use as well as clearest, in my opinion.

How I created a PUT request:

http::Request request("URL");

http::Response response;

// pass parameters as a map
std::map<std::string, std::string> parameters = {
{"hunger", }, {"xp", 22"}, {"poop", "22"}, {"mood", "happy"} };
response = request.send("PUT", parameters, {
"Content-Type: application/x-www-form-urlencoded"
});
banf
  • 39
  • 5
  • There is no HTTP support in C++. And asking for an external library recommendation is off topic. Please read [ask] and then edit your question. – Richard Critten Oct 06 '19 at 15:30
  • It's far more complicated to implement such protocols from scratch than using libraries. Why do you can't use libraries like cpr? You don't need CMake to link against them. If curl and Boost.Asio is to complicated for you you should think about using another programming language. – Thomas Sablik Oct 06 '19 at 15:32
  • I don't think sending HTTP requests in c++ changed dramatically over 10 years. Since there is still no standard way to send the HTTP request you should use one of the libraries out there (which update themselves if necessary), and HTTP haven't changed in 10 years so... – unlut Oct 06 '19 at 15:33
  • I don't know any library that requires CMake. cpr describes the configuration with CMake as an example. You can use it without CMake. – Thomas Sablik Oct 06 '19 at 15:39
  • @RichardCritten - I still very much consider myself a novice to C++, but in my (somewhat) short study/use of the language I haven't yet read/needed HTTP requests in C++. In a language that is (kind-of) glorified as being all-encompassing, how is a beginner supposed to know that the best way to get http functionality is from an external library? – Skewjo Nov 24 '20 at 20:01

1 Answers1

0

I managed to solve my issue using this library. This library seemed to be the easiest to use as well as clearest, in my opinion.

How I created a PUT request:

http::Request request("URL");

http::Response response;

// pass parameters as a map
std::map<std::string, std::string> parameters = {
{"hunger", }, {"xp", 22"}, {"poop", "22"}, {"mood", "happy"} };
response = request.send("PUT", parameters, {
"Content-Type: application/x-www-form-urlencoded"
});
banf
  • 39
  • 5