问题描述
我正在使用apache http客户端连接到远程服务器。远程服务器发送重定向,我想实现我的客户端不会自动跟踪重定向,以便我可以提取propper标头,并为目标做任何我想做的事。
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.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客户端跟随重定向的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!