Return-Path: Delivered-To: apmail-jakarta-httpclient-user-archive@www.apache.org Received: (qmail 58210 invoked from network); 28 Jun 2006 10:57:38 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (209.237.227.199) by minotaur.apache.org with SMTP; 28 Jun 2006 10:57:38 -0000 Received: (qmail 105 invoked by uid 500); 28 Jun 2006 10:57:30 -0000 Delivered-To: apmail-jakarta-httpclient-user-archive@jakarta.apache.org Received: (qmail 99977 invoked by uid 500); 28 Jun 2006 10:57:30 -0000 Mailing-List: contact httpclient-user-help@jakarta.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: "HttpClient User Discussion" Reply-To: "HttpClient User Discussion" Delivered-To: mailing list httpclient-user@jakarta.apache.org Received: (qmail 99963 invoked by uid 99); 28 Jun 2006 10:57:30 -0000 Received: from asf.osuosl.org (HELO asf.osuosl.org) (140.211.166.49) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jun 2006 03:57:30 -0700 X-ASF-Spam-Status: No, hits=0.0 required=10.0 tests= X-Spam-Check-By: apache.org Received-SPF: neutral (asf.osuosl.org: local policy) Received: from [195.186.18.65] (HELO mail19.bluewin.ch) (195.186.18.65) by apache.org (qpsmtpd/0.29) with ESMTP; Wed, 28 Jun 2006 03:57:27 -0700 Received: from [192.168.0.3] (62.203.191.201) by mail19.bluewin.ch (Bluewin 7.3.110.2) id 449253F8002E7870 for httpclient-user@jakarta.apache.org; Wed, 28 Jun 2006 10:57:05 +0000 Subject: Re: Help with cookies From: Oleg Kalnichevski To: HttpClient User Discussion In-Reply-To: References: Content-Type: text/plain Date: Wed, 28 Jun 2006 12:56:54 +0200 Message-Id: <1151492214.25820.3.camel@localhost.localdomain> Mime-Version: 1.0 X-Mailer: Evolution 2.6.1 Content-Transfer-Encoding: 7bit X-Virus-Checked: Checked by ClamAV on apache.org X-Spam-Rating: minotaur.apache.org 1.6.2 0/1000/N Please post a complete wire/context log of the HTTP session http://jakarta.apache.org/commons/httpclient/logging.html Oleg On Tue, 2006-06-27 at 22:32 -0300, Vinicius Carvalho wrote: > Hello there! I'm building a app to get some contents from a remote > site that has authentication (it uses struts, and its just a simple > auth). > Well, here's what I'm doing: > > private boolean authenticate(){ > String url = "http://acme.com/login.do"; > HttpClient client = new HttpClient(); > PostMethod post = new PostMethod(url); > NameValuePair[] data = { new > NameValuePair("email","java.vinicius@gmail.com"), new > NameValuePair("password","123456")}; > post.setRequestBody(data); > try { > client.executeMethod(post); > this.cookies = client.getState().getCookies(); > for(Cookie cookie : cookies){ > System.out.println(cookie.toExternalForm()); > } > } catch (HttpException e) { > e.printStackTrace(); > } catch (IOException e) { > e.printStackTrace(); > }finally{ > post.releaseConnection(); > } > return (this.cookies != null && this.cookies.length > 0); > } > > Well ok, the JSESSIONID cookie is fetched, no problem at all. So i try > to access a forbiden page: > > boolean authenticated = authenticate(); > > if(authenticated){ > HttpState state = new HttpState(); > state.addCookies(cookies); > HttpClient client = new HttpClient(); > client.setState(state); > client.getParams().setCookiePolicy(CookiePolicy.RFC_2109); > GetMethod method = new GetMethod(); > method.setURI(new URI(url,true)); > client.executeMethod(method); > String contents = > method.getResponseBodyAsString(); method.releaseConnection(); > } > > Well, instead of receiving the right page, what I'm getting is a one > of our pages that is shown when a forbidden resource is accessed > without the user having the proper permission. > > What am I doing wrong here, isn't the user already authenticathed? > > Regards > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org > For additional commands, e-mail: httpclient-user-help@jakarta.apache.org > > --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-user-unsubscribe@jakarta.apache.org For additional commands, e-mail: httpclient-user-help@jakarta.apache.org