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

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

问题描述

我有一个返回 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.

有没有一种方法可以在没有 WebClient 跟随的情况下发出一个简单的 HTTP 请求并取回目标位置?

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 设置为 false 来处理重定向自己.

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

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

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