Return-Path: X-Original-To: apmail-hc-httpclient-users-archive@www.apache.org Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id A1E089D12 for ; Thu, 29 Sep 2011 16:36:59 +0000 (UTC) Received: (qmail 81179 invoked by uid 500); 29 Sep 2011 16:36:59 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 81152 invoked by uid 500); 29 Sep 2011 16:36:59 -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 81141 invoked by uid 99); 29 Sep 2011 16:36:59 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Sep 2011 16:36:59 +0000 X-ASF-Spam-Status: No, hits=1.5 required=5.0 tests=FREEMAIL_FROM,HTML_MESSAGE,RCVD_IN_DNSWL_LOW,SPF_PASS X-Spam-Check-By: apache.org Received-SPF: pass (nike.apache.org: domain of predatorvi@gmail.com designates 74.125.82.53 as permitted sender) Received: from [74.125.82.53] (HELO mail-ww0-f53.google.com) (74.125.82.53) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 29 Sep 2011 16:36:53 +0000 Received: by wwg14 with SMTP id 14so1051404wwg.34 for ; Thu, 29 Sep 2011 09:36:33 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=mime-version:in-reply-to:references:from:date:message-id:subject:to :content-type; bh=PJMsy6UdSKqhpa5ZB57Byl8qMQ/zWPKE+IOApE3Rdyc=; b=bmabPLVdPhOp96rVfZ8RsDn47dgVMSzAfQ+YoQsfdp6sx3ebLWlk/wSrgVChodVwqB yT0riOqudsPzXlR0Y1l1tr/N5g30vVEk/Dj0nSwB0y4ESdBHa4PQYDKvEBB0vr2s2MkH h+HxGBBUNjP51bGGkYYGmOoDbvY3GNXBKghwk= Received: by 10.216.132.129 with SMTP id o1mr1502034wei.3.1317314193163; Thu, 29 Sep 2011 09:36:33 -0700 (PDT) MIME-Version: 1.0 Received: by 10.216.4.13 with HTTP; Thu, 29 Sep 2011 09:36:13 -0700 (PDT) In-Reply-To: References: <22BC5FF8-3624-402B-9649-79CB5A37E956@transpac.com> From: Jeff Date: Thu, 29 Sep 2011 10:36:13 -0600 Message-ID: Subject: Re: HttpClient 4.1.2 and redirect handling... To: HttpClient User Discussion Content-Type: multipart/alternative; boundary=0016e6de03a48a868604ae171c66 X-Virus-Checked: Checked by ClamAV on apache.org --0016e6de03a48a868604ae171c66 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: quoted-printable Thanks for the responses. Works beautifully! Looking forward to 4.2 as well.... On Thu, Sep 29, 2011 at 9:54 AM, Vasile Alin wrot= e: > You can also have a look at > > https://svn.apache.org/repos/asf/httpcomponents/httpclient/trunk/httpclie= nt/src/main/java/org/apache/http/impl/client/LaxRedirectStrategy.java > available starting with 4.2. > > On 29 September 2011 08:20, Ken Krugler > wrote: > > This is a topic that comes up repeatedly on the list. > > > > From Ryan Smith's response to the same question about a year ago: > > > >> Redirecting POSTs breaks RFC standards. You need to extend and > implement > >> your own RedirectHandler/RedirectStrategy and tell HttpClient to use i= t > >> instead of the default one. > > > > I see that section 5.3 in the tutorial already says "HttpClient handles > all types of redirects automatically, except those explicitly prohibited = by > the HTTP specification as requiring user intervention". Though I don't kn= ow > what the next bit of text on the tutorial is trying to say: "See Other > (status code 303) redirects on POST and PUT requests..." > > > > There's some code at Stack Overflow (first hit on > http://lmgtfy.com/?q=3Dhttpclient+4+doesn%27t+redirect+post) that might b= e > useful. > > > > > http://stackoverflow.com/questions/3658721/httpclient-4-error-302-how-to-= redirect > > > > -- Ken > > > > On Sep 28, 2011, at 8:54pm, Jeff wrote: > > > >> Being new to the v4.x HttpClient (and rusty with older versions...ack)= , > this > >> may be something obvious that I've just missed. > >> > >> The tutorial (section 5.3) states that HttpClient handles most redirec= t > >> automatically. I have the following set: > >> > >> > >> > httpclient.getParams().setBooleanParameter(ClientPNames.HANDLE_REDIRECTS, > >> true); > >> > >> > httpclient.getParams().setBooleanParameter(ClientPNames.ALLOW_CIRCULAR_RE= DIRECTS, > >> true); > >> > >> I create the HttpPost for the form POST which seems to be working: > >> > >> post =3D new HttpPost(baseUrl + "/userLoginManual.aspx"); > >> > >> List formparams =3D new ArrayList()= ; > >> formparams.add(new BasicNameValuePair("postlogin_path", > >> "/offers/consent.aspx")); > >> formparams.add(new BasicNameValuePair("login", username)); > >> formparams.add(new BasicNameValuePair("password", password)); > >> UrlEncodedFormEntity entity =3D new UrlEncodedFormEntity(formpara= ms, > >> "UTF-8"); > >> post.setEntity(entity); > >> > >> response =3D httpclient.execute(post, localContext); > >> > >> code =3D response.getStatusLine().getStatusCode(); > >> > >> But the response is "302 - Moved Temporarily". This is part of the > normal > >> process, but I would have expected HttpClient to handle it and return = me > a > >> 200. > >> > >> Since I really only needed the cookies returned after successful auth,= I > am > >> doing : > >> > >> try { > >> respStr =3D responseHandler.handleResponse(response); > >> } catch (HttpResponseException hrex) { > >> post.abort(); > >> } > >> in order to consume the response which is throwing the > HttpResponseException > >> (due to the 302) and calling post.abort(). This works for me, but I > >> wondered why the redirect isn't happening automagically. > >> > >> Any light/knowledge/insight is much appreciated. > >> > >> -- > >> Jeff Vincent > >> predatorvi@gmail.com > >> See my LinkedIn profile at: > >> http://www.linkedin.com/in/rjeffreyvincent > >> I =E2=99=A5 DropBox !! > > > > -------------------------- > > Ken Krugler > > +1 530-210-6378 > > http://bixolabs.com > > custom big data solutions & training > > Hadoop, Cascading, Mahout & Solr > > > > > > > > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org > For additional commands, e-mail: httpclient-users-help@hc.apache.org > > --=20 Jeff Vincent predatorvi@gmail.com See my LinkedIn profile at: http://www.linkedin.com/in/rjeffreyvincent I =E2=99=A5 DropBox !! --0016e6de03a48a868604ae171c66--