如何防止 apache http 客户端跟随重定向 [英] How to prevent apache http client from following a redirect
问题描述
我正在使用 apache http 客户端连接到远程服务器.远程服务器发送一个重定向,我想实现我的客户端不会自动跟随重定向,这样我就可以提取正确的标头并对目标做任何我想做的事情.
I'm connecting to a remote server with apache http client. the remote server sends a redirect, and i want to achieve that my client isn't following the redirect automatically so that i can extract the propper header and do whatever i want with the target.
我正在寻找一个简单的工作代码示例(复制粘贴)停止自动重定向跟随行为.
i'm looking for a simple working code sample (copy paste) that stops the automatic redirect following behaviour.
我发现 防止 HttpClient 4 跟随重定向,但似乎我用 HttpClient 4.0 (GA) 实现它太愚蠢了
i found Preventing HttpClient 4 from following redirect, but it seems i'm too stupid to implement it with HttpClient 4.0 (GA)
推荐答案
默认的 HttpClient
实现在可配置性方面非常有限,但您可以通过使用 HttpClient 的布尔参数 http 来控制重定向处理.protocol.handle-redirects
.
The default HttpClient
implementation is pretty limited in configurability, but you can control the redirect handling by using HttpClient's boolean parameter http.protocol.handle-redirects
.
请参阅文档参考.
这篇关于如何防止 apache http 客户端跟随重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!