开发者

How to know redirect URL [duplicate]

This question already has answers here: Closed 12 years ago.

Possible Duplicate:

A way to figure out redirection URL

C# Issue:

If we type the following url (see warning) http://migre.me/13rQa

It will redirect to oooooo1.ru

I like to know the redirected URL from C#. Anybody knows how to do it.

P.S: These mentioned URL could be virus affe开发者_如何学Pythoncted. Please use on own risk


If migre.me has some kind of an API, maybe they can provide you with a "preview" of the site you'll be redirected to.

If they don't, you'll have to create an HttpWebRequest and see the Uri of the response.

e.g.

WebRequest request = WebRequest.Create("http://migre.me/13rQa");
var response = request.GetResponse();

With that code, the response.ResponseUri property will have the address you'll be redirected.

Hope this helps you


If you're using HttpWebRequest, set AllowAutoRedirect to false. You'll then get to see the redirect yourself. Note that this only applies to HTTP-level redirects, not meta redirects within HTML.

(I don't know offhand whether it will throw an exception, but even if it does you can examine the response to find out the status code and the data including the redirection.)

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜