小编pig*_*toe的帖子

如何将此curl命令转换为libcurl

我使用这样的curl命令成功登录www.tistory.com。

curl -c cookie.txt -d "loginId=xxx&password=xxx&form_id=authForm" https://www.tistory.com/auth/login
Run Code Online (Sandbox Code Playgroud)

而且...为了在我的 C++ 项目中使用它,我将它转换为 libcurl,如下所示。

CURL *curl;
CURLcode res;
char *location;
long response_code;

curl = curl_easy_init();

if (curl) {
    curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
    curl_easy_setopt(curl, CURLOPT_URL, "https://www.tistory.com/auth/login");
    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie.txt");

    const char* postData = "loginId=xxx&password=xxx&form_id=authForm";

    curl_easy_setopt(curl, CURLOPT_POST, 1L);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, postData);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDSIZE, strlen(postData));

    curl_easy_setopt(curl, CURLOPT_SSL_VERIFYPEER, 0L);

    res = curl_easy_perform(curl);

    ......
}

......
Run Code Online (Sandbox Code Playgroud)

这个转换后的代码不起作用。并且 cookie.txt 文件也没有保存。我不知道哪里出了问题或者我错过了什么。有人告诉我一下。提前致谢。

这是结果。

在此输入图像描述

c++ curl libcurl

3
推荐指数
1
解决办法
3112
查看次数

标签 统计

c++ ×1

curl ×1

libcurl ×1