Advertisement
Guest User

Untitled

a guest
Mar 31st, 2017
124
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.54 KB | None | 0 0
  1. ServicePointManager.Expect100Continue = true;
  2. ServicePointManager.SecurityProtocol = SecurityProtocolType.Tls12;
  3.  
  4. CookieCollection cookies = new CookieCollection();
  5. HttpWebRequest request = (HttpWebRequest)WebRequest.Create("my provider logon page here");
  6. request.CookieContainer = new CookieContainer();
  7. request.CookieContainer.Add(cookies);
  8. HttpWebResponse response = (HttpWebResponse)request.GetResponse();
  9. cookies = response.Cookies;
  10.  
  11. string getUrl = "my provider logon page here";
  12. string postData = String.Format("UserName={0}&Password={1}&userType={2}&rememberMe={3}", "login", "password", "FON", "true");
  13. HttpWebRequest getRequest = (HttpWebRequest)WebRequest.Create(getUrl);
  14. getRequest.CookieContainer = new CookieContainer();
  15. getRequest.CookieContainer.Add(cookies);
  16. getRequest.Method = WebRequestMethods.Http.Post;
  17. getRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.3; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/57.0.2987.110 Safari/537.36";
  18. getRequest.AllowWriteStreamBuffering = true;
  19. getRequest.ProtocolVersion = HttpVersion.Version11;
  20. getRequest.AllowAutoRedirect = true;
  21. getRequest.ContentType = "application/x-www-form-urlencoded";
  22.  
  23. byte[] byteArray = Encoding.ASCII.GetBytes(postData);
  24. getRequest.ContentLength = byteArray.Length;
  25. Stream newStream = getRequest.GetRequestStream();
  26. newStream.Write(byteArray, 0, byteArray.Length);
  27. newStream.Close();
  28. HttpWebResponse getResponse = (HttpWebResponse)getRequest.GetResponse();
  29. using (StreamReader sr = new StreamReader(getResponse.GetResponseStream()))
  30. {
  31. string sourceCode = sr.ReadToEnd();
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement