我使用这样的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 文件也没有保存。我不知道哪里出了问题或者我错过了什么。有人告诉我一下。提前致谢。
这是结果。
Dan*_*erg 10
将curl 命令行转换为C 代码的最佳方法是使用--libcurl code.c命令行选项。
当这样做并将输出与代码片段进行比较时,两个程序之间的唯一区别似乎是User-Agent:使用 libcurl 的程序中缺少标头。
| 归档时间: |
|
| 查看次数: |
3112 次 |
| 最近记录: |