我的代码尝试导航通过外部进程提供给它的 Url,但最近我发现 HTTPWebRequest 重定向中的一个错误
URL 为 http://ask.bitauto.com/TreeAsk/index.aspx
我发现,当指定了 HTTP-Referer 时,此 url 在浏览器中成功导航,但即使分配了 .Refer,.Net 的 WebRequest 也会失败(不提供任何异常),以防 AutoRedirects Enabled 失败并出现 MaxRedirect 达到异常
根据 MSDN
“如果AllowAutoRedirect属性为true,则当请求重定向到另一个站点时,会自动设置Referer属性。”
这是否意味着同一站点中的重定向会以不同的方式处理。如果有人知道如何解决这个问题,请告诉我。
提前致谢
My Code Tries to navigate Url provided to it via external processes, but recently I found a bug in HTTPWebRequest Redirection
the URL in case was http://ask.bitauto.com/TreeAsk/index.aspx
What I found is this url gets NAvigated in browser successfully when HTTP-Referer is specified but .Net's WebRequest fails (without providing any exception) even when .Refer is assigned, in case of AutoRedirects Enabled is failed with MaxRedirect reached exception
According to MSDN
"If the AllowAutoRedirect property is true, the Referer property is set automatically when the request is redirected to another site."
does this mean redirects with in same site are handled differently. Please let me know if someone has any idea how to solve this.
Thanks in Advance
发布评论
评论(1)
我认为这个问题的根源在于http://ask.bitauto.com/TreeAsk/index。 .aspx.
跟随您的链接(因此有一个 stackoverflow 的引荐来源网址)会得到这个答案:
注意空的
Location
标头 - 来自服务器的回复是重定向到...什么都没有。编辑:
似乎只有在您没有引荐来源网址或非ask.bitauto.com引荐来源网址时才会显示空重定向页面。将目标 URL 设置为引荐来源网址会产生
200 OK
答案。编辑 2:
空 Location 标头行为不符合 RFC2616,似乎不同的网络代理在不同的方式。
我认为最可靠的解决方案是指定 HTTPWebRequest。您的请求中的推荐人。
I think the root of this problem is within http://ask.bitauto.com/TreeAsk/index.aspx.
Following your link (thus having a referrer to stackoverflow) results in this answer:
Notice the empty
Location
header - the reply from the server is a redirect to... nothing.Edit:
It seems like the empty redirect page is only shown if you have no referrer or a non-ask.bitauto.com referrer. Setting the target URL as referrer results in a
200 OK
answer.Edit 2:
The empty Location header behavior isn't according to RFC2616, and it seems like different web agents react to it in different way.
I think the most robust solution for you is to specify HTTPWebRequest.Referrer in your request.