在c ++中向libcurl GET添加参数 [英] Add paramethers to libcurl GET in c++

查看:1043
本文介绍了在c ++中向libcurl GET添加参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在变量中添加一些额外的数据到使用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 methid做类似的事情?

GET 只是将参数附加到网址,例如

  http://some.host.com/some/path?variable1=value1&variable2=value2 

我相信你已经看过了!


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?

解决方案

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 GET添加参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆