
please wait
#include <stdio.h> #include <string.h> #include <stdlib.h> #include <errno.h> #include <time.h> #include <curl.h> static void print_cookies(CURL *curl) // funkcja otrzymuje uchwyt sesji { CURLcode res; // utworzenie zmiennej res struct curl_slist *cookies=NULL; //utworzenie struktury struct curl_slist *nc; //utworzenie drugiej struktury int i; //pomocnicza zmienna printf("Cookies, curl knows:\n"); //chwali sie ze otrzymał nastepujace cookies res = curl_easy_getinfo(curl, CURLINFO_COOKIELIST, &cookies); //wyciaga informacje o cookies i zrzuca ją do struktury if (res != CURLE_OK) {//jesli ok fprintf(stderr, "Curl curl_easy_getinfo failed: %s\n", curl_easy_strerror(res));//jesli blad wysyła tą inforamcje exit(1);//jesli blad konczy funkcje } nc = cookies, i = 1; while (nc) {//dopoki nc nie jest 0 czyli dopoki cookies istnieje printf("[%d]: %s\n", i, nc->data); nc = nc->next; i++; } if (i == 1) { printf("(none)\n"); } curl_slist_free_all(cookies);// koniec listy } int main(void) { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL);//tworzy sesje curl = curl_easy_init(); if (curl) { curl_easy_setopt(curl, CURLOPT_URL, "http://google.com/");//ustala uchwyt sesji curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L);//zeby cookies pobierało curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */ res = curl_easy_perform(curl);// wychwytuje błędy sesji if (res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } else fprintf(stderr, "prawidlowo rozpoczeto sesje"); print_cookies(curl); printf("Erasing curl's knowledge of cookies!\n"); curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); } curl_global_cleanup(); return 0; } |
|
|
|
|
* About to connect() to www.google.com port 80 * Trying 173.194.113.144... * connected * Connected to www.google.com (173.194.113.144) port 80 > GET / HTTP/1.1 Host: www.google.com Accept: */* < HTTP/1.1 302 Found < Location: http://www.google.pl/?gws_rd=cr < Cache-Control: private < Content-Type: text/html; charset=UTF-8 * Added cookie PREF="ID=380d3b08e23eeebc:FF=0:TM=1375437202:LM=1375437202:S=ex0x XBbVjaBIr1Uk" for domain google.com, path /, expire 1438512802 < Set-Cookie: PREF=ID=380d3b08e23eeebc:FF=0:TM=1375437202:LM=1375437202:S=ex0xXB bVjaBIr1Uk; expires=Sun, 02-Aug-2015 09:53:22 GMT; path=/; domain=.google.com * Added cookie NID="67=lAWE3VCmydWgBsR3Mp7GYVQkv2kVUAPEbyVeoxwNV8RzyfP0kvRHEgeSx 9AosaKqdIKKjcnV2T_3utNB0wlr-uz-_iPOUYp1-JVtjhANtlzXm1OrYYz2_w-xp_bA9ZFc" for dom ain google.com, path /, expire 1391248402 < Set-Cookie: NID=67=lAWE3VCmydWgBsR3Mp7GYVQkv2kVUAPEbyVeoxwNV8RzyfP0kvRHEgeSx9A osaKqdIKKjcnV2T_3utNB0wlr-uz-_iPOUYp1-JVtjhANtlzXm1OrYYz2_w-xp_bA9ZFc; expires=S at, 01-Feb-2014 09:53:22 GMT; path=/; domain=.google.com; HttpOnly < P3P: CP="This is not a P3P policy! See http://www.google.com/support/accounts/ bin/answer.py?hl=en&answer=151657 for more info." < Date: Fri, 02 Aug 2013 09:53:22 GMT < Server: gws < Content-Length: 228 < X-XSS-Protection: 1; mode=block < X-Frame-Options: SAMEORIGIN <HTML><HEAD><meta http-equiv="content-type" content="text/html;charset=utf-8"> <TITLE>302 Moved</TITLE></HEAD><BODY> <H1>302 Moved</H1> The document has moved <A HREF="http://www.google.pl/?gws_rd=cr">here</A>. </BODY></HTML> * Connection #0 to host www.google.com left intact prawidlowo rozpoczeto sesjeCookies, curl knows: Curl curl_easy_getinfo failed: a libcurl function was given a bad argument |
curl_easy_setopt(curl, CURLOPT_FOLLOWLOCATION, 1L);
$ lsb_release -d Description: Debian GNU/Linux 7.1 (wheezy) $ curl-config --version libcurl 7.26.0 $ g++ -v . . . gcc version 4.7.2 (Debian 4.7.2-5) |
Debian GNU/Linux unstable (sid) libcurl 7.31.0 gcc version 4.7.3 (Debian 4.7.3-6) |
FreeBsd 9.1 RELEASE libcurl 7.24.0 gcc version 4.2.1 |
Can you give me link with this system and program, which you use to compiling |