从Web客户端获取位置上的HTTP 302重定向? [英] Getting the location from a WebClient on a HTTP 302 Redirect?

查看:275
本文介绍了从Web客户端获取位置上的HTTP 302重定向?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个返回一个HTTP 302重定向的URL,我想获得它重定向到URL。

I have a URL that returns a HTTP 302 redirect, and I would like to get the URL it redirects to.

的问题是,System.Net.WebClient似乎实际上遵循它,这是不好的。 HttpWebRequest的,似乎这样做。

The problem is that System.Net.WebClient seems to actually follow it, which is bad. HttpWebRequest seems to do the same.

有没有一种方法,使一个简单的HTTP请求,并取回目标位置,而不WebClient的下面呢?

Is there a way to make a simple HTTP Request and get back the target Location without the WebClient following it?

我很想做原始套接字通信作为HTTP是很简单的,但该网站使用HTTPS,我不想做握手。

I'm tempted to do raw socket communication as HTTP is simple enough, but the site uses HTTPS and I don't want to do the Handshaking.

最后,我不在乎我使用的类,我只是不希望它遵循HTTP 302重定向:)

At the end, I don't care which class I use, I just don't want it to follow HTTP 302 Redirects :)

推荐答案

的HttpWebRequest 你可以设置 AllowAutoRedirect 处理重定向自己。

On HttpWebRequest you can set AllowAutoRedirect to false to handle the redirect yourself.

这篇关于从Web客户端获取位置上的HTTP 302重定向?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆