Click here to Skip to main content
14,865,447 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Can anybody tells me that after finding a redirection URI, how to do the next step?

UPDATE from OP:
Thanks for the reply, I am refering the url How to use HttpWebRequest and HttpWebResponse in .NET[^]

but I am stuck in a place.

My intension is as below, say I a going to login to Wordpress.

1. I gave a web request to http://wordpress[^]

2. Then my POST url is https://en.wordpress.com/wp-login.ph[^] with login parameters

3. But there is a redirection here, so, I wanted to know, after the step one what I have to do? If I post the webrequest with parameters its not login in because of the redirection, I dont know how to proceed....
Posted
Updated 11-Oct-10 20:50pm
v2
Comments
Bikash Shrestha From Nepal 12-Oct-10 2:39am
   
Plz make us clear , what you want to do
Sandeep Mewara 12-Oct-10 2:51am
   
You can always use 'Improve Question' button and edit/update your question.
Ankur\m/ 12-Oct-10 3:48am
   
[moved from answer]
Maxpayne_0 wrote:
I dont understand the reply, but I need to help by understanding the concept of my doubt pls

This might be what you're looking for:

C#
var wr = (HttpWebRequest)HttpWebRequest.Create(new Uri("http://wordpress.com/"));
wr.AllowAutoRedirect = true;


VS metadata throws up this:

C#
// Summary:
//     Gets or sets a value that indicates whether the request should follow redirection
//     responses.
//
// Returns:
//     true if the request should automatically follow redirection responses from
//     the Internet resource; otherwise, false. The default value is true.
public bool AllowAutoRedirect { get; set; }
   
I answered a question similar to this earlier. Some of it may be helpful. You can find it at Downloading files without direct address through C# program[^].

This can be very difficult and the way I worked it was to use HttpFox within Firefox to monitor the actual HTTP requests that Firefox followed when doing this. The things that you need to watch for are the Referrer and the Cookies.

Wordpress is a bit different than in the other article, so here's what I did and using it, I was able to get the HTML of the https://en.wordpress.com site (filling in log and pwd with actual login credentials).

C#
//Set up the request
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(@"https://en.wordpress.com/wp-login.php");
myRequest.Referer = @"https://en.wordpress.com";
myRequest.Method = "POST";
myRequest.Host = "en.wordpress.com";

//set up the post data
string postData=@"log=username&pwd=password&testcookie=1&redirect_to=https://wordpress.com&rememberme=forever&submit";
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postData);
myRequest.ContentLength = data.Length;

//create the cookie container
myRequest.CookieContainer = new CookieContainer();

//finish setting up the request
myRequest.ContentType ="application/x-www-form-urlencoded";
myRequest.AllowAutoRedirect = true;

//send the data
Stream newStream = myRequest.GetRequestStream();
newStream.Write(data, 0, data.Length);
newStream.Close();

//get the response
string pageSource = "";

using (HttpWebResponse response = (HttpWebResponse)myRequest.GetResponse())
{
    using (StreamReader reader = new StreamReader(response.GetResponseStream()))
    {
        pageSource = reader.ReadToEnd();
    }
}
   
v3

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900