Httpwebrequest/Httpwebresponse-重定向计数 [英] Httpwebrequest / Httpwebresponse - Redirect Count

查看:82
本文介绍了Httpwebrequest/Httpwebresponse-重定向计数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图弄清楚我的Web请求被重定向多少次之后才最终找到最终内容.

I'm trying to figure out how many times my web request was redirected before I finally landed at the end content.

我正在创建我的Web请求,如下所示:

I'm creating my web request as follows:

var httpRequest = (HttpWebRequest) WebRequest.Create("some arb path");
httpRequest.AllowAutoRedirect = followRedirects; 

我看过以下URL http://msdn.microsoft.com/zh-CN/library/system.net.httpwebrequest.maximumautomaticredirections.aspx

但是,我不想强​​加该限制.我实际上希望它遵循所有重定向(并不是真的想要引用所有URL),而是例如说您已被重定向X次".

However, I do not want to impose the limit. I actually want it to follow all redirects (not really wanting a reference to all the URL's), but just for example saying "You have been redirected X times".

我希望有一种快速的方法,因为目前我假设我必须捕获所有3xx代码并为每个代码创建一个新请求(希望不是!).

I hope there's a quick way to do it as currently I'm assuming I would have to capture all 3xx codes and create a new request for each (hopefully not!).

推荐答案

无法实现您想要的目标.您将必须捕获每个3xx请求,并使用重定向的位置标头发出一个新请求.

There is no way to achieve what you want. You will have to capture each 3xx request and issue a new one with the location header of the redirect.

但是,如果您想使用本机C/C ++代码并直接写入WININET(即IE使用的库),它将为您(通过回调机制)为每次发生的重定向提供通知.

However, if you want to use native C/C++ code and write directly to WININET (which is the library used by IE) it will provide you (via a callback mechanism) notification for each redirect that happened.

这篇关于Httpwebrequest/Httpwebresponse-重定向计数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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