他の同様の質問がありますが、これも私も読んでいますが、私の問題はユニークです。私はmojang.comにログインしようとしています(依頼しないでください)。その後のリクエストではログインしたままです。しかし、私がPOSTリクエストをログインページに送ったとき、私はログインページをダンプするだけです。ログインページをPASTにするにはどうしたらいいですか?LibCURLのウェブサイトへのログイン
私はクッキーエンジンを起動しており、クッキーは正常に記録され、印刷されていると思われますが、使用されていない可能性があります。
私の目標は、ログインが成功した後、このページにアクセスすることです:https://account.mojang.com/me
session* mojang_login(const char *user, const char *pass,
const char *q1, const char *q2, const char *q3)
{
const char *url = "https://account.mojang.com/login";
const char *payload = construct_payload(user, pass);
const char *ua =
"Mozilla/5.0 (X11; Linux x86_64; rv:55.0) Gecko/20100101 Firefox/55.0";
char errbuf[CURL_ERROR_SIZE] = {0};
CURL *curl;
CURLcode res;
curl = curl_easy_init();
if (!curl)
{
fprintf(stderr, "Failed to initialize curl\n");
return NULL;
}
curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);
curl_easy_setopt(curl, CURLOPT_ERRORBUFFER, errbuf);
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
curl_easy_setopt(curl, CURLOPT_URL, url);
curl_easy_setopt(curl, CURLOPT_USERAGENT, ua);
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "");
curl_easy_setopt(curl, CURLOPT_POST, 1L);
curl_easy_setopt(curl, CURLOPT_POSTFIELDS, payload);
res = curl_easy_perform(curl);
free((void*) payload);
if (res != CURLE_OK)
{
curl_err(res, errbuf);
return NULL;
}
struct curl_slist *cookies;
res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies);
if (res != CURLE_OK)
{
curl_err(res, errbuf);
return NULL;
}
while (cookies)
{
printf("\nCOOKIE DATA: %s\n", cookies->data);
cookies = cookies->next;
}
session *s1 = NULL; /* safe_malloc(sizeof(session));*/
curl_easy_cleanup(curl);
return s1;
}