Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

libcurl C++ adding http get parameters

Tags:

c++

libcurl

I am new to C++ development and I have been trying to work with libcurl.

I basically am looking for a function that lets me enter in parameters similar to the -d flag in curl.

for example if I were to just send a url request in curl directly or the web browser the url would look like 'https://www.example.com/hello.json?whoisawesome=me&whosucks=yomomma'

then how could i feed it to libcurl not as just one url as suggested in the accepted answer of this question: Add paramethers to libcurl GET in c++

but as parameters I could add? I am hoping the call would automatically 'clean up' the text (e.g., to support ampersands(&) and equal signs (=) in the string. I'm sure there's other cases but that's the only one i can think of for now). Of course I could make a function that cleans up the string myself but I'd like to know if there's one built into libcurl.

I checked the api doc but I guuss I was not familiar enough to successfully navigate it to find what I needed.

Thanks for your time

like image 501
ThinkBonobo Avatar asked Mar 21 '23 15:03

ThinkBonobo


1 Answers

  1. As already said, the full URL including GET parameters has to be built manually.
  2. Sanity checks, like stripping leading or trailing spaces, is not a responsibility of libcurl.
  3. To URL-encode the (sanitized) value part of a parameter you can use curl_easy_escape. The key part should be in your hand anyway.
like image 186
Martin Trenkmann Avatar answered Mar 28 '23 12:03

Martin Trenkmann