Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 18402 invoked from network); 19 Feb 2010 10:10:08 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 19 Feb 2010 10:10:08 -0000 Received: (qmail 47880 invoked by uid 500); 19 Feb 2010 10:10:08 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 47818 invoked by uid 500); 19 Feb 2010 10:10:07 -0000 Mailing-List: contact httpclient-users-help@hc.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-users@hc.apache.org Received: (qmail 47808 invoked by uid 99); 19 Feb 2010 10:10:07 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Feb 2010 10:10:07 +0000 X-ASF-Spam-Status: No, hits=3.7 required=10.0 tests=HTML_MESSAGE,SPF_PASS,WEIRD_PORT X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of blomqvist.andreas@gmail.com designates 209.85.218.223 as permitted sender) Received: from [209.85.218.223] (HELO mail-bw0-f223.google.com) (209.85.218.223) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 19 Feb 2010 10:09:57 +0000 Received: by bwz23 with SMTP id 23so1075752bwz.38 for ; Fri, 19 Feb 2010 02:09:37 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:in-reply-to:references :date:message-id:subject:from:to:content-type; bh=PpmUBiHT5RmYK8Y8VsoMm7IBLA6ARutrLyItsBJOH2E=; b=U8Q0iKoumz0kpySLlb8MkuvjJtUBK4QtYMlfYLHiXQQIJy0GPgzoGV97qu/vTyIxg5 Rut0znaj2uY+qA0EKjV/10OwuacmM2e1qyZsOGwQmc9aAm1xxBEryGNujh3WC8DgrTn2 pa4TXmT27ooI2Q7zviCvirGEr4O0cXDcKixng= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:date:message-id:subject:from:to :content-type; b=rzfRd+/fZVnZ32Mm79r8fVevVe1Sc+IDA7/x7p2EPeKGh5vTx5gvUtKQO3Ca/ncjMB EFCYlR7GRFFW6gUV3Ch0dFw7F6TVXdOAWgRKo2nI3GTuWoFPNvZEOFjHnJutI/5KG2d2 rRpZMUAK7ebbjAOTdG/vPCI644afNL1SDVj4w= MIME-Version: 1.0 Received: by 10.239.134.13 with SMTP id 13mr1182582hbx.93.1266574177044; Fri, 19 Feb 2010 02:09:37 -0800 (PST) In-Reply-To: <4B7E5FB8.9070505@apache.org> References: <9f2e3cdc1002180549n2fa53535x954b200f8472e005@mail.gmail.com> <4B7DA053.8010307@apache.org> <9f2e3cdc1002182353m52101a8fw62144abb5f629aa8@mail.gmail.com> <9f2e3cdc1002190123u100931c5s74fb4fb71d3529ec@mail.gmail.com> <4B7E5FB8.9070505@apache.org> Date: Fri, 19 Feb 2010 11:09:36 +0100 Message-ID: <9f2e3cdc1002190209s71d79372scb18c3e61d0b24ef@mail.gmail.com> Subject: Re: login problems with post and redirect. From: Andreas Blomqvist To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=001485f03c08e78b37047ff1474b X-Virus-Checked: Checked by ClamAV on apache.org --001485f03c08e78b37047ff1474b Content-Type: text/plain; charset=ISO-8859-1 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 wrote: > Andreas Blomqvist wrote: > >> Thats for httpClient 3 ? >> >> /A >> >> On 19 February 2010 08:56, Avlesh Singh 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 < >>> blomqvist.andreas@gmail.com> 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.BasicHttpContext@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 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 nvps = new ArrayList(); >>>>>> 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: httpclient-users-unsubscribe@hc.apache.org >>>>> For additional commands, e-mail: httpclient-users-help@hc.apache.org >>>>> >>>>> >>>>> >> > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org > For additional commands, e-mail: httpclient-users-help@hc.apache.org > > --001485f03c08e78b37047ff1474b--