Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- static void getResponse(string loginUrl, string secondUrl, string username, string password, string cookieName = null)
- {
- HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginUrl);
- request.Method = "POST";
- CookieContainer container = new CookieContainer();
- if (cookieName != null)
- {
- container.Add(new Cookie(cookieName, username, "/", new Uri(loginUrl).Host));
- }
- string postData = String.Format("Username={0}&Password={1}", username, password);
- ServicePointManager.ServerCertificateValidationCallback = new System.Net.Security.RemoteCertificateValidationCallback(AcceptAllCertifications);
- byte[] byteArray = Encoding.UTF8.GetBytes(postData);
- request.ContentType = "application/x-www-form-urlencoded";
- request.ContentLength = byteArray.Length;
- Stream dataStream = request.GetRequestStream();
- dataStream.Write(byteArray, 0, byteArray.Length);
- dataStream.Close();
- WebResponse response = request.GetResponse();
- dataStream = response.GetResponseStream();
- //Need to somehow find the name of the inputs for username and password, as I think I
- //currently have them incorrect.
- StreamReader reader = new StreamReader(dataStream);
- string responseFromServer = reader.ReadToEnd();
- using (StreamWriter outfile = new StreamWriter(@"C:\Users\jacko\Documents\tempFile1.xml"))
- {
- outfile.Write(responseFromServer.ToString());
- }
- reader.Close();
- dataStream.Close();
- response.Close();
- request = (HttpWebRequest)WebRequest.Create(secondUrl);
- request.CookieContainer = container;
- response = request.GetResponse();
- dataStream = response.GetResponseStream();
- reader = new StreamReader(dataStream);
- responseFromServer = reader.ReadToEnd();
- using (StreamWriter outfile = new StreamWriter(@"C:\Users\jacko\Documents\tempFile.xml"))
- {
- outfile.Write(responseFromServer.ToString());
- }
- reader.Close();
- dataStream.Close();
- response.Close();
- }
- public static bool AcceptAllCertifications(object sender,
- System.Security.Cryptography.X509Certificates.X509Certificate certification,
- System.Security.Cryptography.X509Certificates.X509Chain chain,
- System.Net.Security.SslPolicyErrors sslPolicyErrors)
- {
- return true;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement