On Wed, 2011-06-08 at 14:00 +0400, Vladimir Loginov wrote: > http://pastebin.com/8cyd3Rii > > I need to login to some servers with httpclient. There is a code which > runs 2 versions. Without arguments will login at server with Java Api, > and with any arguments will login the same server with httpclient. But > in second case we will not get the response from server (after > "Answer: "). Why it happens and how to fix it? >
This is because the server responds back with a 302 status (Moved Temporarily). Per requirement of the HTTP specification 302 response to a POST request may _not_ be handled automatically without a user confirmation. You have two options: change the url in your code to http://e.mail.ru/cgi-bin/start in order to avoid the redirect or force HttpClient to handle redirect by using a custom RedirectStrategy Hope this helps Oleg --- [DEBUG] SingleClientConnManager - Get connection for route HttpRoute[{s}->https://auth.mail.ru] [DEBUG] DefaultClientConnectionOperator - Connecting to auth.mail.ru/94.100.184.17:443 [DEBUG] RequestAddCookies - CookieSpec selected: compatibility [DEBUG] RequestAuthCache - Auth cache not set in the context [DEBUG] DefaultHttpClient - Attempt 1 to execute request [DEBUG] DefaultClientConnection - Sending request: POST /cgi-bin/auth HTTP/1.1 [DEBUG] headers - >> POST /cgi-bin/auth HTTP/1.1 [DEBUG] headers - >> Content-Length: 0 [DEBUG] headers - >> Host: auth.mail.ru [DEBUG] headers - >> Connection: Keep-Alive [DEBUG] headers - >> User-Agent: Apache-HttpClient/4.1.1 (java 1.5) [DEBUG] DefaultClientConnection - Receiving response: HTTP/1.1 302 OK [DEBUG] headers - << HTTP/1.1 302 OK [DEBUG] headers - << Server: nginx/0.7.62 [DEBUG] headers - << Date: Fri, 10 Jun 2011 08:02:58 GMT [DEBUG] headers - << Content-Type: text/plain [DEBUG] headers - << Connection: close [DEBUG] headers - << Location: http://e.mail.ru/cgi-bin/start [DEBUG] headers - << Set-Cookie: mrcu=DACE4DF1CFB244EFC12D0100007F; expires=Mon, 07 Jun 2021 08:02:58 GMT; path=/; domain=.mail.ru [DEBUG] headers - << Content-Length: 0 [DEBUG] headers - << X-Host: f201.mail.ru [DEBUG] headers - << X-XSS-Protection: 0 [DEBUG] ResponseProcessCookies - Cookie accepted: "[version: 0][name: mrcu][value: DACE4DF1CFB244EFC12D0100007F][domain: .mail.ru][path: /][expiry: Mon Jun 07 09:02:58 GMT+01:00 2021]". Answer: [DEBUG] SingleClientConnManager - Releasing connection org.apache.http.impl.conn.SingleClientConnManager$ConnAdapter@1d95492 [DEBUG] SingleClientConnManager - Released connection open but not reusable. [DEBUG] DefaultClientConnection - Connection shut down --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
