簡體   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