Advertisement
dram

Untitled

Jul 8th, 2014
196
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.75 KB | None | 0 0
  1. int main()
  2. {
  3. std::string user = "test1015";
  4. std::string pass = "qwerty123";
  5.  
  6. curl_global_init(CURL_GLOBAL_ALL);
  7. CURL * myHandle;
  8. CURLcode result; // We’ll store the result of CURL’s webpage retrieval, for simple error checking.
  9. struct BufferStruct output; // Create an instance of out BufferStruct to accept LCs output
  10. output.buffer = NULL;
  11. output.size = 0;
  12. struct curl_slist *headers = NULL;
  13. headers = curl_slist_append(headers, "application/x-www-form-urlencoded; charset=UTF-8");
  14. myHandle = curl_easy_init();
  15.  
  16. /* Notice the lack of major error checking, for brevity */
  17. curl_easy_setopt(myHandle, CURLOPT_WRITEFUNCTION, WriteMemoryCallback); // Passing the function pointer to LC
  18. curl_easy_setopt(myHandle, CURLOPT_WRITEDATA, (void *)&output); // Passing our BufferStruct to LC
  19. curl_easy_setopt(myHandle, CURLOPT_USERAGENT, "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.3) Gecko/20070309 Firefox/2.0.0.3");
  20. //curl_easy_setopt(myHandle, CURLOPT_AUTOREFERER, 1);
  21. curl_easy_setopt(myHandle, CURLOPT_HTTPAUTH, CURLAUTH_ANY);
  22. curl_easy_setopt(myHandle, CURLOPT_ENCODING, "UTF-8");
  23. curl_easy_setopt(myHandle, CURLOPT_COOKIEJAR, "cookie.txt");
  24. curl_easy_setopt(myHandle, CURLOPT_COOKIEFILE, "cookie.txt");
  25. curl_easy_setopt(myHandle, CURLOPT_POST, TRUE);
  26. //curl_easy_setopt(myHandle, CURLOPT_FORBID_REUSE, 1); //mimic real world use
  27. curl_easy_setopt(myHandle, CURLOPT_URL, "http://www.plemiona.pl/index.php?action=login&show_server_selection=0");
  28. curl_easy_setopt(myHandle, CURLOPT_REFERER, "http://www.plemiona.pl/index.php");
  29. //
  30. curl_easy_setopt(myHandle, CURLOPT_HTTPHEADER, headers);
  31. curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, "user=test1015&password=qwerty123&cookie=true&clear=true&server=pl84");
  32. result = curl_easy_perform(myHandle);
  33. if (result == CURLE_OK){
  34. //logowanie cd
  35. result = curl_easy_setopt(myHandle, CURLOPT_URL, "http://www.google.pl");
  36. if (result == CURLE_OK){
  37. curl_easy_setopt(myHandle, CURLOPT_REFERER, "http://www.google.pl");
  38. curl_easy_setopt(myHandle, CURLOPT_POST, TRUE);
  39. headers = curl_slist_append(headers, "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8");
  40. curl_easy_setopt(myHandle, CURLOPT_HTTPHEADER, headers);
  41. curl_easy_setopt(myHandle, CURLOPT_POSTFIELDS, "user=test1015&password=70d02a81bb359ffbc3d682699c8649e9de97883f");
  42.  
  43. curl_easy_perform(myHandle);
  44. curl_easy_setopt(myHandle, CURLOPT_WRITEDATA, (void *)&output); // Passing our BufferStruct to LC
  45.  
  46. FILE * fp;
  47. fopen_s(&fp, "example12.html", "w");
  48. if (!fp)
  49. return 1;
  50. fprintf(fp, output.buffer);
  51. fclose(fp);
  52.  
  53. if (output.buffer)
  54. {
  55. free(output.buffer);
  56. output.buffer = 0;
  57. output.size = 0;
  58. }
  59. }
  60. }
  61. curl_easy_cleanup(myHandle);
  62.  
  63. return 0;
  64. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement