cURL获得发布回复的麻烦

时间:2017-05-19 06:30:05

标签: c++ curl libcurl

我正在尝试创建一个连接到服务器的基本登录程序,但是当我尝试将响应从发布请求保存到变量时,我根本不会得到响应但是如果我没有&# 39;试着保存它我得到回应,我不确定我做错了什么,任何帮助都会受到赞赏,欢呼。

int post(string str1, string str2, string str3) {

    string query = "user=" + str1 + "&pass=" + str2;

    CURL *curl;
    CURLcode res;
    curl = curl_easy_init();

    if (curl) {

        curl_easy_setopt(curl, CURLOPT_URL, "http://www.vlone.cc/pwned.php");
        curl_easy_setopt(curl, CURLOPT_POSTFIELDS, query.c_str());

        // when i comment out these 2 lines I get a response otherwise I don't
        curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, write_to_string);
        curl_easy_setopt(curl, CURLOPT_WRITEDATA, &str3);

        res = curl_easy_perform(curl);
        curl_easy_cleanup(curl);
    }

    curl_global_cleanup();

    return 0;
}

写入字符串

size_t write_to_string(void *ptr, size_t size, size_t count, void *stream) {
    ((string*)stream)->append((char*)ptr, 0, size*count);
    return size*count;
}

0 个答案:

没有答案