我用C++(cli)写了一个小程序,它允许在网站上启动一个请求。与C++进行交互
#include <iostream>
#include <string>
#include <curl/curl.h>
static size_t WriteCallback(void *contents, size_t size, size_t nmemb, void *userp)
{
((std::string*)userp)->append((char*)contents, size * nmemb);
return size * nmemb;
}
int main(void)
{
CURL *curl;
CURLcode res;
std::string readBuffer;
curl = curl_easy_init();
if(curl) {
curl_easy_setopt(curl, CURLOPT_URL, "http://localhost/?id=1&hash=123456");
curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, WriteCallback);
curl_easy_setopt(curl, CURLOPT_WRITEDATA, &readBuffer);
res = curl_easy_perform(curl);
curl_easy_cleanup(curl);
std::cout << readBuffer << std::endl;
}
return 0;
}
此代码工作得很好,符合我要求
我需要创建一个交互式版本修改URL的变量的任务。该程序的输出 例子:
./my_prog
What content do you want to add in the variable id?
1
What content do you want to add in the hash variable?
123456879
而且这些问题后,将推出卷曲与查询的问题的结果。
你能解释我可以做与c + +的交互?
_“你能解释我可以做与c + +的交互?”_使用'std :: cin'? – user0042
@ user0042! :D谢谢 – Julien