Thursday, April 28, 2011

HttpWebRequest.Address vs HttpWebResponse.ResponseUri

Whats the difference between these two properties?

To put into context, I am determining if a redirect occurs if our ResponseUri != RequestUri.

While a redirect occurs regardless the url http://adage.com/adages/article?article%5Fid=140560 will provide a different ResponseUri (http://adage.com/adages/post.php) than the Address (http://adage.com/adages/post?article%5Fid=140560).

It appears the ResponseUri takes the Content-Location header and uses it while the Address maintains the correct location.

Would it be correct to compare the RequestUri to the HttpWebRequest.Address to check for redirects?

From stackoverflow
  • Have you thought about setting request.AllowAutoRedirect=false and then reissuing the request on a redirect?

    The Uri comparison should also work fine, although I am not sure of all the edge cases

    Pat : I have considered setting the AllowAutoRedirect to false, however if I am able to handle the redirect with the current comparison I would venture for that.
  • Yes, comparing request.RequestUri and request.Address is the way to go. At least in Mono response.ResponseUri is the same as request.Address.

0 comments:

Post a Comment