int main(void) { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if (curl) { char nline[256]; curl_easy_setopt(curl, CURLOPT_URL, "http://bbs.pediy.com/login.php?do=login"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, "abce.cookie"); /* just to start the cookie engine *///会使curl下一次发请求时从指定的文件中读取cookie。 curl_easy_setopt(curl, CURLOPT_POSTFIELDS, POSTFIELDS); // CURLOPT_POSTFIELDS: POST参数 res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); printf("Erasing curl's knowledge of cookies!\n"); curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); //CURLOPT_COOKIELIST 会把指定的cookie字符串列表加入easy handle维护的cookie列表中。 // 每个cookie字符串要么符合HTTP response header的"Set-Cookie: NAME=VALUE;..."格式,要么符合Netscape cookie格式。 print_cookies(curl); printf("-----------------------------------------------\n" "Setting a cookie \"PREF\" via cookie interface:\n"); #ifdef WIN32 #define snprintf sprintf_s #endif /* Netscape format cookie */ snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", ".google.com", "TRUE", "/", "FALSE", (unsigned long)time(NULL) + 31337UL, "PREF", "hello google, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if (res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } /* HTTP-header style cookie */ snprintf(nline, sizeof(nline), "Set-Cookie: OLD_PREF=3d141414bf4209321; " "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if (res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } } else { fprintf(stderr, "Curl init failed!\n"); return 1; } curl_global_cleanup(); return 0; }
int main(void) { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if(curl) { char nline[256]; curl_easy_setopt(curl, CURLOPT_URL, "http://www.example.com/"); curl_easy_setopt(curl, CURLOPT_VERBOSE, 1L); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* start cookie engine */ res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); printf("Erasing curl's knowledge of cookies!\n"); curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); print_cookies(curl); printf("-----------------------------------------------\n" "Setting a cookie \"PREF\" via cookie interface:\n"); #ifdef WIN32 #define snprintf _snprintf #endif /* Netscape format cookie */ snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", ".google.com", "TRUE", "/", "FALSE", (unsigned long)time(NULL) + 31337UL, "PREF", "hello google, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if(res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } /* HTTP-header style cookie. If you use the Set-Cookie format and don't specify a domain then the cookie is sent for any domain and will not be modified, likely not what you intended. Starting in 7.43.0 any-domain cookies will not be exported either. For more information refer to the CURLOPT_COOKIELIST documentation. */ snprintf(nline, sizeof(nline), "Set-Cookie: OLD_PREF=3d141414bf4209321; " "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if(res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); res = curl_easy_perform(curl); if(res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } curl_easy_cleanup(curl); } else { fprintf(stderr, "Curl init failed!\n"); return 1; } curl_global_cleanup(); return 0; }
int main(void) { CURL *curl; CURLcode res; curl_global_init(CURL_GLOBAL_ALL); curl = curl_easy_init(); if (curl) { char nline[256]; curl_easy_setopt(curl, CURLOPT_URL, "http://www.google.com/"); /* google.com sets "PREF" cookie */ curl_easy_setopt(curl, CURLOPT_VERBOSE, 1); curl_easy_setopt(curl, CURLOPT_COOKIEFILE, ""); /* just to start the cookie engine */ res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); printf("Erasing curl's knowledge of cookies!\n"); curl_easy_setopt(curl, CURLOPT_COOKIELIST, "ALL"); print_cookies(curl); printf("-----------------------------------------------\n" "Setting a cookie \"PREF\" via cookie interface:\n"); #ifdef WIN32 #define snprintf _snprintf #endif /* Netscape format cookie */ snprintf(nline, sizeof(nline), "%s\t%s\t%s\t%s\t%lu\t%s\t%s", ".google.com", "TRUE", "/", "FALSE", time(NULL) + 31337, "PREF", "hello google, i like you very much!"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if (res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } /* HTTP-header style cookie */ snprintf(nline, sizeof(nline), "Set-Cookie: OLD_PREF=3d141414bf4209321; " "expires=Sun, 17-Jan-2038 19:14:07 GMT; path=/; domain=.google.com"); res = curl_easy_setopt(curl, CURLOPT_COOKIELIST, nline); if (res != CURLE_OK) { fprintf(stderr, "Curl curl_easy_setopt failed: %s\n", curl_easy_strerror(res)); return 1; } print_cookies(curl); res = curl_easy_perform(curl); if (res != CURLE_OK) { fprintf(stderr, "Curl perform failed: %s\n", curl_easy_strerror(res)); return 1; } } else { fprintf(stderr, "Curl init failed!\n"); return 1; } curl_global_cleanup(); return 0; }
int main(int argc, char *argv[]) { hashset_t set = hashset_create(); hashset_add(set,"leer"); curl_global_init(CURL_GLOBAL_ALL); CURL * myHandle = curl_easy_init(); char md5Password [32]; struct string s; struct string g; init_string(&s); init_string(&g); int i; /* char password[BUFSIZ]; char name[BUFSIZ]; printf("Enter Username: \n"); fgets(name, BUFSIZ, stdin); printf("Enter Password: \n"); fgets(password,BUFSIZ,stdin); cleaner(name); cleaner(password); */ //temp char password [] = "569dgBAh#6Kv2^e9z^ALFiOq"; char name [] = "Foxi"; //temp hashPassword(password, md5Password); doLogin(name, md5Password, myHandle); sleep(3); getSecretToken(myHandle,&s); sleep(3); char* tokenarray = (char*) malloc((s.len + 3) * sizeof (char)); strcpy(tokenarray, s.ptr); findSecretToken(tokenarray, s.len); //Hier muss die URL hin auf welche Danke gesagt wird! char danke [] = "http://usenet-4all.info/forum/showthread.php?t=637647"; doTanks(danke,&g, myHandle); char* pidarray = (char*) malloc((g.len + 3) * sizeof (char)); strcpy(pidarray, g.ptr); findPid(pidarray, g.len, set); //Ab hier habe ich alle PIDS! pushthanks(tokenarray,danke,set,myHandle); print_cookies(myHandle); curl_easy_cleanup(myHandle); free(s.ptr); free(tokenarray); free(pidarray); free(g.ptr); return 0; }