Reputation: 3295
This question relates to Migrate from Commons HttpClient to HttpComponents Client (migrating from HttpClient 3 to HttpClient 4).
I can access a link physically in a browser but when I try to access same link using HttpClient 4.1.13 I get HTTP error 301 ("Move Permanent").
When accessing same link using HttpClient 3.1 I don't get HTTP error 301.
What could be causing such anormally? Could it be a setting that I am missing under HC 4 that makes it behave that way?
Upvotes: 0
Views: 4405
Reputation: 27538
This can be happening because the origin server(s) respond differently to requests with different User-Agent
header.
Upvotes: 2
Reputation: 128829
First, 301 isn't an "error". The 3xx responses are "redirection" responses. 4xx and 5xx are the error series.
In response to your question, per RFC 2616, a user agent may not automatically handle redirects if the request method isn't GET or HEAD. I'd guess you're doing a POST. HttpClient 4 is more strict in its compliance to the HTTP spec than its predecessor, and it definitely complies with the spec on this point, so that's probably why you're seeing this problem.
Upvotes: 2
Reputation: 718788
If you are using the HC 4.x HttpClient service, it should be dealing with redirects automatically. At least, that's what the documentation says. (I note that there are some configuration properties, but the documentation says that automatic redirection handling is enabled by default.)
Upvotes: 0