dan richardson
dan richardson

Reputation: 3939

WebRequest follow redirect

I have a page (url a) which submits a form programmatically using a WebRequest.
The page that accepts the form request does a bunch of stuff and then redirects to another page (url b)

Is it possible at all to perform the webrequest (which reads, processes and redirects the form request), which then makes the current page (url a) redirect to the webrequest end location (url b).

I currently have;

  HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(url + postVars);  
  myRequest.AllowAutoRedirect = true;

  HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();  
  myRequest.AllowAutoRedirect = true;

  // Read response stream
  StreamReader myStream = new StreamReader(myResponse.GetResponseStream());  
  string response = myStream.ReadToEnd();  
  myResponse.Close();

This all works fine and everything happens as expected apart from after the myResponse.Close(), I am still at url a, not url b, i.e the page that the request was made from is still the active page

Any ideas on where I am going wrong? Or any better ideas?

I need to be able to.

Does that make sense?
Thanks in advance.

Upvotes: 1

Views: 13148

Answers (1)

BrokenGlass
BrokenGlass

Reputation: 160852

I think you are confused about how redirects work - you make a request to Url A, but may ultimately receive a response from Url B if you get redirected there (and AllowAutoRedirect is set to true).

The client / requestor does not get redirected in any shape or form, just where the response to a client's request is coming from is. So your "active page" of course never changes.

Upvotes: 4

Related Questions