我使用这样的curl命令成功登录了www.tistory.com。
curl -c cookie.txt -d "loginId=xxx&password=xxx&form_id=authForm" https://www.tistory.com/auth/login
然后...要在我的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);
......
}
......
此转换后的代码不起作用。 cookie.txt文件也没有保存。我不知道哪里出了问题或我错过了什么。有人让我知道。预先感谢。
这是结果。
答案 0 :(得分:-1)
这两个请求之间唯一的区别似乎是在libcurl情况下缺少User-Agent:
头。