我想使用 C++ 在变量中添加一些附加数据到 HTTP GET。当我使用 HTTP POST 发出请求时,我会这样做:
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);
但是我怎样才能使用 GET 方法做类似的事情呢?
最佳答案
对于 GET
只需将参数附加到 URL,例如
http://some.host.com/some/path?variable1=value1&variable2=value2
我相信你以前见过它!
关于c++ - 在 C++ 中向 libcurl GET 添加参数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19582838/