|
-
Jun 27th, 2009, 05:38 PM
#1
Thread Starter
New Member
WebClient - Am I logging in right, or being redirected right?
Hi
I'm trying to figure out a way to log into a new site that a 3rd party vendor has provided us by using a script.
I'm new to web related coding.
Its a ticketing site. We have to log into it.
If you attempt to load up a URL directly to a ticket, you are redirected to the login window. Once you log on, you can then view the ticket.
Code:
private void Form1_Load(object sender, EventArgs e)
{
string postData = "userName=Removed&password=Removed";
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("End URL's location");
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
request.Method = "POST";
request.AllowAutoRedirect = false;
Stream requestStream = request.GetRequestStream();
byte[] postBytes = Encoding.ASCII.GetBytes(postData);
requestStream.Write(postBytes, 0, postBytes.Length);
requestStream.Close();
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
Console.WriteLine(new StreamReader(response.GetResponseStream()).ReadToEnd());
Console.WriteLine("Headers:");
Console.WriteLine(response.Headers.ToString());
string url = "End URL's location";
System.Diagnostics.Process.Start(url);
}
The info that I keep downloading is the login's page html code. Not the ticket page's code.
Console's results (made it a bit easier to read):
<input type="hidden" name="redirectAction" value="Removed_request_dashboard">
<input type="hidden" name="userName" value="Removed">
<input type="hidden" name="inc_id" value="5045176">
<input type="hidden" name="password" value="Removed">
There must be a tiny bit of code I'm missing. The login info is there, but its not logging me in. Or perhaps its logging me in but not directing me properly afterwards.
Last edited by Raygar; Jun 27th, 2009 at 05:42 PM.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|