2

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?

skaffman
  • 398,947
  • 96
  • 818
  • 769
Mojo
  • 2,687
  • 5
  • 30
  • 42
  • can you give us a sequence of locations it doesn't follow? I mean something like http://site1.example.com -> http://site2.example.com -> ... – Shcheklein Feb 25 '11 at 20:56
  • The host is an internal host, and the redirect is to the same host, same protocol. The initial call is a POST, and the return is a redirect to a GET page that shows the results of the POST. – Mojo Feb 28 '11 at 22:33

2 Answers2

1

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.

ok2c
  • 26,450
  • 5
  • 63
  • 71
  • I guess the most frustrating part is "may" and "may not" without the docs indicating what the actual conditions are. The solution (naturally) is to read the source for the DefaultRedirectStrategy. – Mojo Mar 02 '11 at 17:17
0

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

Community
  • 1
  • 1
Shcheklein
  • 5,979
  • 7
  • 44
  • 53
  • That was certainly a possibility, but the original call and the redirect returned both point to https protocol, on the same host. – Mojo Feb 28 '11 at 22:32