简体   繁体   English

尽管进行了设置,但Apache HttpComponents并未遵循重定向请求

[英]Apache HttpComponents does not follow redirect request despite setting

I'm doing a POST to a web server of a MultipartEntity to upload a file. 我正在执行POST到MultipartEntity的Web服务器以上传文件。 Apache HttpComponents version 4.1. Apache HttpComponents版本4.1。

The response I get is a 302 redirect. 我得到的响应是302重定向。 If I use a BasicResponseHandler that throws a ClientProtocolException. 如果我使用抛出ClientProtocolException的BasicResponseHandler。 (The JavaDoc for BasicResponseHandler says that client may follow a redirect, which is pretty vague!) (BasicResponseHandler的JavaDoc表示客户端可能会遵循重定向,这非常模糊!)

The docs led me to believe that the client would automatically follow a redirect and return that response. 该文档使我相信客户端将自动遵循重定向并返回该响应。 I explicitly set HANDLE_REDIRECTS true in the client parameters. 我在客户端参数中明确将HANDLE_REDIRECTS设置为true。

What am I missing here? 我在这里想念什么?

Redirects of some request types (mainly entity enclosing ones such as POST and PUT) MAY NOT be executed automatically per requirements of the HTTP specification. 某些请求类型的重定向(主要是实体包围的请求,例如POST和PUT) 可能不会根据HTTP规范的要求自动执行。 You can override the default behaviour of HttpClient by using a custom RedirectStrategy. 您可以使用自定义RedirectStrategy覆盖HttpClient的默认行为。

May be it's the same issue as here: URLConnection Doesn't Follow Redirect . 可能是这里的问题相同: URLConnection不遵循Redirect It follows only the same protocol, and doesn't redirect from HTTP to HTTPS (or some other combination of different protocols). 它仅遵循相同的协议,并且不会从HTTP重定向到HTTPS(或其他不同协议的组合)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM