Hi I'm confused. Im using httpclient, httpcore and httpmime 4.0.1 jars. Is that not version 4 of HttpClient ?
My code is trying to login in on a webpage by posting a form. But i'm not getting logged in until i make a second call with this code. What doesnt look right? the code or the logs (or both :) ) Thx A On 19 February 2010 10:54, Oleg Kalnichevski <[email protected]> wrote: > Andreas Blomqvist wrote: > >> Thats for httpClient 3 ? >> >> /A >> >> On 19 February 2010 08:56, Avlesh Singh <[email protected]> wrote: >> >> It says redirect is disabled? How do enable it? I thought redirect was on >>>> by default, but did not work for POST >>>> >>>> Looking for - HttpMethod#followRedirects() ? >>> >>> >>> http://hc.apache.org/httpclient-3.x/apidocs/org/apache/commons/httpclient/HttpMethod.html#setFollowRedirects%28boolean%29 >>> >>> Cheers >>> Avlesh >>> >>> On Fri, Feb 19, 2010 at 1:23 PM, Andreas Blomqvist < >>> [email protected]> wrote: >>> >>> Hi >>>> >>>> Here some loggs from when I tried to logon: >>>> >>>> [java] The server is running at http://localhost:8282/ >>>> [java] Got request method login >>>> [java] 2010-feb-19 07:48:45 >>>> org.apache.http.client.protocol.RequestAddCookies process >>>> [java] FIN: CookieSpec selected: best-match >>>> [java] 2010-feb-19 07:48:45 >>>> org.apache.http.impl.client.DefaultRequestDirector execute >>>> [java] FIN: Attempt 1 to execute request >>>> [java] 2010-feb-19 07:48:46 >>>> org.apache.commons.httpclient.HttpMethodDirector isRedirectNeeded >>>> [java] INFO: Redirect requested but followRedirects is disabled >>>> >>> > This log comes from HttpClient 3 (org.apache.commons.httpclient name > space), whereas all others come from HttpClient 4 (org.apache.http.client > name space). > > I have no idea what your application is supposed to do, but this certainly > does not look right to me. > > Oleg > > > [java] 2010-feb-19 07:48:46 >>>> org.apache.http.client.protocol.ResponseProcessCookies processCookies >>>> [java] FIN: Cookie accepted: "[version: 0][name: PHPSESSID][value: >>>> 9l8gtdf85tn4gitqjs0hg2f551][domain: schema.sthlm.friskissvettis.se >>>> >>> ][path: >>> >>>> /][expiry: null]". >>>> [java] http://url_to_server/index.php?func=do_login >>>> [java] 2010-feb-19 07:48:46 >>>> org.apache.http.client.protocol.RequestAddCookies process >>>> [java] FIN: CookieSpec selected: best-match >>>> [java] 2010-feb-19 07:48:46 >>>> org.apache.http.client.protocol.RequestAddCookies process >>>> [java] FIN: Cookie [version: 0][name: PHPSESSID][value: >>>> 9l8gtdf85tn4gitqjs0hg2f551][domain: schema.sthlm.friskissvettis.se >>>> >>> ][path: >>> >>>> /][expiry: null] match [schema.sthlm.friskissvettis.se:80/index.php] >>>> [java] 2010-feb-19 07:48:46 >>>> org.apache.http.impl.client.DefaultRequestDirector execute >>>> [java] FIN: Attempt 1 to execute request >>>> [java] 2010-feb-19 07:48:47 >>>> org.apache.http.client.protocol.ResponseProcessCookies processCookies >>>> [java] FIN: Cookie accepted: "[version: 0][name: PHPSESSID][value: >>>> 9tteoedfpeugqb81d2750dk3q5][domain: schema.sthlm.friskissvettis.se >>>> >>> ][path: >>> >>>> /][expiry: null]". >>>> [java] 2010-feb-19 07:48:47 >>>> org.apache.http.client.protocol.RequestAddCookies process >>>> [java] FIN: CookieSpec selected: best-match >>>> [java] 2010-feb-19 07:48:47 >>>> org.apache.http.client.protocol.RequestAddCookies process >>>> [java] FIN: Cookie [version: 0][name: PHPSESSID][value: >>>> 9tteoedfpeugqb81d2750dk3q5][domain: schema.sthlm.friskissvettis.se >>>> >>> ][path: >>> >>>> /][expiry: null] match [schema.sthlm.friskissvettis.se:80/index.php] >>>> [java] context: org.apache.http.protocol.basichttpcont...@148e798 >>>> [java] 2010-feb-19 07:48:47 >>>> org.apache.http.impl.client.DefaultRequestDirector execute >>>> [java] FIN: Attempt 1 to execute request >>>> [java] 2010-feb-19 07:48:47 >>>> org.apache.http.client.protocol.ResponseProcessCookies processCookies >>>> [java] FIN: Cookie accepted: "[version: 0][name: PHPSESSID][value: >>>> 7ugatbbqeku112d8atm9b9qr34][domain: schema.sthlm.friskissvettis.se >>>> >>> ][path: >>> >>>> /][expiry: null]". >>>> >>>> >>>> It says redirect is disabled? How do enable it? I thought redirect was >>>> on >>>> by >>>> default, but did not work for POST >>>> >>>> /A >>>> >>>> >>>> On 18 February 2010 21:17, Oleg Kalnichevski <[email protected]> wrote: >>>> >>>> Andreas Blomqvist wrote: >>>>> >>>>> Hi >>>>>> >>>>>> Doing a POST login to a site (which I dont control) and manually >>>>>> redirecting. However I am not getting logged in until I make a second >>>>>> >>>>> call >>>> >>>>> to the login method. Why? >>>>>> >>>>>> My code for login : >>>>>> >>>>>> private HttpContext login(DefaultHttpClient httpClient, String >>>>>> >>>>> button, >>> >>>> String user, String pass) throws UnsupportedEncodingException, >>>>>> >>>>> IOException >>>> >>>>> { >>>>>> >>>>>> HttpResponse response = null; >>>>>> HttpEntity entity = null; >>>>>> HttpPost httpost = new HttpPost(BASE_URL + >>>>>> "/index.php?func=do_login"); >>>>>> >>>>>> List<NameValuePair> nvps = new ArrayList<NameValuePair>(); >>>>>> nvps.add(new BasicNameValuePair("btn_login", button)); >>>>>> nvps.add(new BasicNameValuePair("txt_login", user)); >>>>>> nvps.add(new BasicNameValuePair("psw_password", pass)); >>>>>> >>>>>> httpost.setEntity(new UrlEncodedFormEntity(nvps, HTTP.UTF_8)); >>>>>> >>>>>> HttpContext context = new BasicHttpContext(); >>>>>> response = httpClient.execute(httpost, context); >>>>>> >>>>>> System.out.println("Post status is " + >>>>>> >>>>> response.getStatusLine()); >>> >>>> >>>>>> entity = response.getEntity(); >>>>>> if (entity != null) { >>>>>> entity.consumeContent(); >>>>>> } >>>>>> >>>>>> HttpUriRequest request = (HttpUriRequest) context.getAttribute( >>>>>> ExecutionContext.HTTP_REQUEST); >>>>>> >>>>>> String uri = BASE_URL + request.getURI().toString(); >>>>>> >>>>>> System.out.println("uri in login " + uri); >>>>>> >>>>>> HttpGet redirect = new HttpGet(uri); >>>>>> response = httpClient.execute(redirect, context); >>>>>> >>>>>> System.out.println("Redirect HttpGet status is " + >>>>>> response.getStatusLine()); >>>>>> >>>>>> >>>>>> entity = response.getEntity(); >>>>>> if (entity != null) { >>>>>> entity.consumeContent(); >>>>>> } >>>>>> >>>>>> return context; >>>>>> } >>>>>> >>>>>> After a call to this method I get output: (checking login status is >>>>>> >>>>> method >>>> >>>>> I >>>>>> made to check for att logout link on the page. >>>>>> >>>>>> [java] Post status is HTTP/1.1 302 >>>>>> [java] uri in login url_to_first_page >>>>>> [java] Redirect HttpGet status is HTTP/1.1 200 >>>>>> [java] Checking login statuts: false >>>>>> >>>>>> >>>>>> Any thoughts? >>>>>> >>>>>> /A >>>>>> >>>>>> >>>>>> Post wire log >>>>> >>>>> http://hc.apache.org/httpcomponents-client/logging.html >>>>> >>>>> --------------------------------------------------------------------- >>>>> To unsubscribe, e-mail: [email protected] >>>>> For additional commands, e-mail: [email protected] >>>>> >>>>> >>>>> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: [email protected] > For additional commands, e-mail: [email protected] > >
