I want to add some additional data in variable to HTTP GET using c++. When I make request using HTTP POST I do it like that:
curl_easy_setopt(curl, CURLOPT_U
Some support of this now exist (since curl version 7.62). The '?'
and '&'
are added automatically but I currently see no way of adding the parameters and values separately so they still have to be created with a '='
between them.
// Create URL
CURLUcode result;
CURLU *url = curl_url();
char *urlStr;
result = curl_url_set(url, CURLUPART_URL, "https://example.com/hello.json", 0);
if(!result) {
const char paramValue1[] = "param1=value1";
const char paramValue2[] = "param2=value2";
// Add paramters
result = curl_url_set(url, CURLUPART_QUERY, paramValue1, CURLU_APPENDQUERY);
result = curl_url_set(url, CURLUPART_QUERY, paramValue2, CURLU_APPENDQUERY);
// Convert URL to string for printing
result = curl_url_get(url, CURLUPART_URL, &urlStr, 0);
printf("New URL: %s", urlStr);
}
curl_url_cleanup(url);
// Output: New URL: https://example.com/hello.json?param1=value1¶m2=value2
References
[1] https://curl.haxx.se/libcurl/c/curl_url_set.html
For GET
just append the parameters to the URL, like
http://some.host.com/some/path?variable1=value1&variable2=value2
I'm sure you've seen it before!