Add paramethers to libcurl GET in c++

2019-03-03 02:27发布

问题:

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_URL, path);
    curl_formadd(&beginPostList, &endPostList, CURLFORM_COPYNAME, "variable1", CURLFORM_COPYCONTENTS, variable1.c_str(), CURLFORM_END);
    curl_formadd(&beginPostList, &endPostList, CURLFORM_COPYNAME, "variable2", CURLFORM_COPYCONTENTS, variable2.c_str(), CURLFORM_END);
    curl_formadd(&beginPostList, &endPostList, CURLFORM_COPYNAME, "variable3", CURLFORM_COPYCONTENTS, variable3.c_str(), CURLFORM_END);

    curl_easy_setopt(curl, CURLOPT_POST, true);
    curl_easy_setopt(curl, CURLOPT_HTTPPOST, beginPostList);

But how can I do similar thing using GET methid?

回答1:

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!



标签: c++ libcurl