Jus*_*tin 22
这很容易做到
假设您已经创建了一个名为myRequest的HttpWebRequest
// don't allow redirects, they are allowed by default so we're going to override
myRequest.AllowAutoRedirect = false;
// send the request
HttpWebResponse response = myRequest.GetResponse();
// check the header for a Location value
if( response.Headers["Location"] == null )
{
// null means no redirect
}
else
{
// anything non null means we got a redirect
}
Run Code Online (Sandbox Code Playgroud)
请原谅任何编译错误我没有VS就在我面前,但我过去曾用过这个来检查重定向.
Luc*_*ero 14
该HttpWebRequest有一个属性AllowAutoRedirect,你可以设置为false(它始终是真正的WebClient),然后拿到LocationHTTP标头.