Mojo
Mojo

Reputation: 2687

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?

Upvotes: 2

Views: 1842

Answers (2)

ok2c
ok2c

Reputation: 27538

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.

Upvotes: 1

Shcheklein
Shcheklein

Reputation: 6294

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).

Upvotes: 0

Related Questions