Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- //Trust all certificates
- System.Net.ServicePointManager.ServerCertificateValidationCallback =
- ((sender, certificate, chain, sslPolicyErrors) => true);
- //Отправляем запрос на первое получение куков для дальнейшей авторизации
- byte[] buffer = Encoding.ASCII.GetBytes("login_username=testmanny14&login_password=1qaz2wsx&login=%C2%F5%EE%E4");
- HttpWebRequest WebReq = (HttpWebRequest)WebRequest.Create("https://dostup.website/http://rutracker.org/forum/login.php");//Строка для Post-запроса
- var cc = new CookieContainer();
- WebReq.CookieContainer = cc;//включаем куки
- WebReq.Method = "POST";
- WebReq.ContentType = "application/x-www-form-urlencoded";
- WebReq.ContentLength = buffer.Length;
- HttpWebResponse WebResp;
- string result;
- Encoding responseEncoding;
- try
- {
- Stream PostData = WebReq.GetRequestStream();
- PostData.Write(buffer, 0, buffer.Length);
- PostData.Close();
- WebResp = (HttpWebResponse)WebReq.GetResponse();
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, " ", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- //Отправляем запрос к странице с торрентом для получения ее содержимого
- var url = URL.Text;
- WebReq = (HttpWebRequest)WebRequest.Create(url);
- WebReq.CookieContainer = cc;
- WebReq.Method = "GET";
- WebReq.ContentType = "application/x-www-form-urlencoded";
- WebResp = (HttpWebResponse)WebReq.GetResponse();
- responseEncoding = Encoding.GetEncoding(WebResp.CharacterSet);
- try
- {
- using (StreamReader sr = new StreamReader(WebResp.GetResponseStream(), responseEncoding))
- {
- result = sr.ReadToEnd();
- }
- }
- catch (Exception ex)
- {
- MessageBox.Show(ex.Message, "Заголовок сообщения", MessageBoxButtons.OK, MessageBoxIcon.Error);
- return;
- }
- //Скачать торрент
- HtmlAgilityPack.HtmlDocument HD = new HtmlAgilityPack.HtmlDocument();
- HD.LoadHtml(result);
- var match = HD.DocumentNode.SelectSingleNode("//a[@class='dl-stub dl-link']").GetAttributeValue("href", "");
- WebReq = (HttpWebRequest)WebRequest.Create("https://dostup.website/http://rutracker.org/forum/" + match.ToString());
- WebReq.CookieContainer = cc;
- WebReq.AllowAutoRedirect = false;
- WebReq.Method = "POST";
- WebReq.Referer = url;
- WebReq.ContentType = "application/x-www-form-urlencoded";
- /*Пишем его в файл*/
- Stream ReceiveStream = WebReq.GetResponse().GetResponseStream();
- string filename = @"D:\MP4\123.torrent";
- byte[] buffer1 = new byte[1024];
- FileStream outFile = new FileStream(filename, FileMode.Create);
- int bytesRead;
- while ((bytesRead = ReceiveStream.Read(buffer1, 0, buffer.Length)) != 0)
- outFile.Write(buffer1, 0, bytesRead);
- outFile.Close();
- MessageBox.Show("Файл загружен!");
- ReceiveStream.Close();
- WebReq.GetResponse().Close();
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement