Advertisement
Guest User

Untitled

a guest
Aug 7th, 2017
117
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.69 KB | None | 0 0
  1. //Trust all certificates
  2. System.Net.ServicePointManager.ServerCertificateValidationCallback =
  3. ((sender, certificate, chain, sslPolicyErrors) => true);
  4.  
  5.  
  6. //Отправляем запрос на первое получение куков для дальнейшей авторизации
  7. byte[] buffer = Encoding.ASCII.GetBytes("login_username=testmanny14&login_password=1qaz2wsx&login=%C2%F5%EE%E4");
  8. HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("https://dostup.website/http://rutracker.org/forum/login.php");//Строка для Post-запроса
  9.  
  10. var cc = new CookieContainer();
  11. WebReq.CookieContainer = cc;//включаем куки
  12. WebReq.Method = "POST";
  13. WebReq.ContentType = "application/x-www-form-urlencoded";
  14. WebReq.ContentLength = buffer.Length;
  15. HttpWebResponse WebResp;
  16. string result;
  17. Encoding responseEncoding;
  18. try
  19. {
  20. Stream PostData = WebReq.GetRequestStream();
  21. PostData.Write(buffer, 0, buffer.Length);
  22. PostData.Close();
  23. WebResp = (HttpWebResponse)WebReq.GetResponse();
  24.  
  25. }
  26. catch (Exception ex)
  27. {
  28. MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
  29. return;
  30. }
  31. //Отправляем запрос к странице с торрентом для получения ее содержимого
  32. var url = URL.Text;
  33. WebReq = (HttpWebRequest)WebRequest.Create(url);
  34. WebReq.CookieContainer = cc;
  35. WebReq.Method = "GET";
  36. WebReq.ContentType = "application/x-www-form-urlencoded";
  37. WebResp = (HttpWebResponse)WebReq.GetResponse();
  38.  
  39. responseEncoding = Encoding.GetEncoding(WebResp.CharacterSet);
  40. try
  41. {
  42. using (StreamReader sr = new StreamReader(WebResp.GetResponseStream(), responseEncoding))
  43. {
  44. result = sr.ReadToEnd();
  45. }
  46. }
  47. catch (Exception ex)
  48. {
  49. MessageBox.Show(ex.Message, "Заголовок сообщения", MessageBoxButtons.OK, MessageBoxIcon.Error);
  50. return;
  51. }
  52. //Скачать торрент
  53. HtmlAgilityPack.HtmlDocument HD = new HtmlAgilityPack.HtmlDocument();
  54. HD.LoadHtml(result);
  55. var match = HD.DocumentNode.SelectSingleNode("//a[@class='dl-stub dl-link']").GetAttributeValue("href", "");
  56. WebReq = (HttpWebRequest)WebRequest.Create("https://dostup.website/http://rutracker.org/forum/" + match.ToString());
  57. WebReq.CookieContainer = cc;
  58. WebReq.AllowAutoRedirect = false;
  59. WebReq.Method = "POST";
  60. WebReq.Referer = url;
  61. WebReq.ContentType = "application/x-www-form-urlencoded";
  62.  
  63. /*Пишем его в файл*/
  64.  
  65. Stream ReceiveStream = WebReq.GetResponse().GetResponseStream();
  66.  
  67. string filename = @"D:\MP4\123.torrent";
  68. byte[] buffer1 = new byte[1024];
  69. FileStream outFile = new FileStream(filename, FileMode.Create);
  70. int bytesRead;
  71. while ((bytesRead = ReceiveStream.Read(buffer1, 0, buffer.Length)) != 0)
  72. outFile.Write(buffer1, 0, bytesRead);
  73. outFile.Close();
  74. MessageBox.Show("Файл загружен!");
  75. ReceiveStream.Close();
  76. WebReq.GetResponse().Close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement