我用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