简体   繁体   中英

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. Apache HttpComponents version 4.1.

The response I get is a 302 redirect. If I use a BasicResponseHandler that throws a ClientProtocolException. (The JavaDoc for BasicResponseHandler says that client may follow a redirect, which is pretty vague!)

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.

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. You can override the default behaviour of HttpClient by using a custom RedirectStrategy.

May be it's the same issue as here: URLConnection Doesn't Follow Redirect . It follows only the same protocol, and doesn't redirect from HTTP to HTTPS (or some other combination of different protocols).

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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