Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- using HtmlAgilityPack;
- using System;
- using System.Collections.Specialized;
- using System.IO;
- using System.Net;
- using System.Text;
- using System.Threading.Tasks;
- namespace SemanticForce.TestProject2
- {
- class Program
- {
- static void Main(string[] args)
- {
- Console.OutputEncoding = CodePagesEncodingProvider.Instance.GetEncoding(1251);
- const string baseUrl = "https://forum.0day.kiev.ua";
- const string loginUrl = "https://forum.0day.kiev.ua/index.php?act=Login&CODE=01&CookieDate=1";
- //step 1 get cookie
- HttpWebRequest webRequest = (HttpWebRequest)WebRequest.Create(baseUrl);
- //webRequest.Proxy = new WebProxy("127.0.0.1", 8888);
- webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/5";
- webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
- webRequest.Headers.Add("accept-language","uk");
- webRequest.ContentType = "application/x-www-form-urlencoded";
- HttpWebResponse webResponse = (HttpWebResponse)webRequest.GetResponse();
- string sCookies = String.IsNullOrEmpty(webResponse.Headers["Set-Cookie"])?
- "":webResponse.Headers["Set-Cookie"];
- //step 2 send post request for authorization
- webRequest = (HttpWebRequest)WebRequest.Create(loginUrl);
- webRequest.Method = "POST";
- webRequest.Referer = baseUrl;
- webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/5";
- webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
- webRequest.Headers.Add("accept-language", "uk");
- webRequest.ContentType = "application/x-www-form-urlencoded";
- webRequest.Headers.Add(HttpRequestHeader.Cookie, sCookies);
- webRequest.AllowAutoRedirect = false;
- string sQueryString = "UserName=DarkWarrior&PassWord=mSGes4i7yG3XRzU";
- byte[] byteArr = CodePagesEncodingProvider.Instance.GetEncoding(1251).GetBytes(sQueryString);
- webRequest.ContentLength = byteArr.Length;
- webRequest.GetRequestStream().Write(byteArr, 0, byteArr.Length);
- try
- {
- webResponse = (HttpWebResponse)webRequest.GetResponse();
- }
- catch (WebException e) {
- if (e.Message.Contains("302"))
- webResponse = (HttpWebResponse)e.Response;
- }
- //step 3 load data
- string sLocation = webResponse.Headers["Location"];
- sCookies = "";
- if (!String.IsNullOrEmpty(webResponse.Headers["Set-Cookie"]))
- {
- sCookies = webResponse.Headers["Set-Cookie"];
- }
- webRequest = (HttpWebRequest)HttpWebRequest.Create(loginUrl);
- webRequest.Referer = loginUrl;
- webRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/71.0.3578.80 Safari/5";
- webRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*";
- webRequest.Headers.Add("accept-language", "uk");
- webRequest.ContentType = "application/x-www-form-urlencoded";
- if (!String.IsNullOrEmpty(sCookies))
- {
- webRequest.Headers.Add(HttpRequestHeader.Cookie, sCookies);
- }
- webResponse = (HttpWebResponse)webRequest.GetResponse();
- StreamReader myStreamReader = new StreamReader(webResponse.GetResponseStream(), CodePagesEncodingProvider.Instance.GetEncoding(1251));
- HtmlDocument htmlDoc = new HtmlDocument();
- htmlDoc.LoadHtml(myStreamReader.ReadToEnd());
- var data = htmlDoc.DocumentNode.SelectSingleNode("//div[@id='userlinks']");
- Console.WriteLine(data.InnerHtml);
- Console.ReadKey();
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement