繁体   English   中英

在C中使用libcurl登录到Google

[英]login to google with libcurl in C

我尝试使用C语言中的libcurl库登录google。但是google回答了我:“浏览器的cookie功能已关闭。请打开它。”

这是代码:

#include <stdio.h>
#include <stdlib.h>
#include <curl/curl.h>

size_t get_buffer(void *buffer, size_t size, size_t nmemb, void *userp); 

int main(void)
{
  CURL *curl;
  CURLcode res;
  char *data="service=...&dsh=...&GALX=...&pstMsg=0&dnCon=&checkConnection=&Email=...&Passwd=...";   

  curl = curl_easy_init();
  if(curl) {
    curl_easy_setopt(curl, CURLOPT_URL, "https://accounts.google.com/ServiceLoginAuth");
    curl_easy_setopt(curl, CURLOPT_POST, 1);
    curl_easy_setopt(curl, CURLOPT_POSTFIELDS, data);
    curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1);
    curl_easy_setopt(curl, CURLOPT_COOKIEJAR, "cookie");
    curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "cookie"); 
    curl_easy_setopt(curl, CURLOPT_WRITEFUNCTION, get_buffer);
    res = curl_easy_perform(curl);


    curl_easy_cleanup(curl);
  }
  return 0;
}

任何的想法 ? 谢谢。

您需要两次调用网页才能获取Cookie。 请参见:

http://www.hackthissite.org/articles/read/1078

@“您正在检索网页(包含Cookie!)”:

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM