Return-Path: Delivered-To: apmail-hc-httpclient-users-archive@www.apache.org Received: (qmail 22491 invoked from network); 10 Feb 2009 12:25:47 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.2) by minotaur.apache.org with SMTP; 10 Feb 2009 12:25:47 -0000 Received: (qmail 5725 invoked by uid 500); 10 Feb 2009 12:25:46 -0000 Delivered-To: apmail-hc-httpclient-users-archive@hc.apache.org Received: (qmail 5699 invoked by uid 500); 10 Feb 2009 12:25:45 -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 5687 invoked by uid 99); 10 Feb 2009 12:25:45 -0000 Received: from athena.apache.org (HELO athena.apache.org) (140.211.11.136) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Feb 2009 04:25:45 -0800 X-ASF-Spam-Status: No, hits=4.1 required=10.0 tests=DNS_FROM_OPENWHOIS,SPF_HELO_PASS,SPF_PASS,WEIRD_PORT,WHOIS_MYPRIVREG X-Spam-Check-By: apache.org Received-SPF: pass (athena.apache.org: domain of lists@nabble.com designates 216.139.236.158 as permitted sender) Received: from [216.139.236.158] (HELO kuber.nabble.com) (216.139.236.158) by apache.org (qpsmtpd/0.29) with ESMTP; Tue, 10 Feb 2009 12:25:37 +0000 Received: from isper.nabble.com ([192.168.236.156]) by kuber.nabble.com with esmtp (Exim 4.63) (envelope-from ) id 1LWrfv-00006N-D9 for httpclient-users@hc.apache.org; Tue, 10 Feb 2009 04:25:15 -0800 Message-ID: <21932530.post@talk.nabble.com> Date: Tue, 10 Feb 2009 04:25:15 -0800 (PST) From: caffeine zombie To: httpclient-users@hc.apache.org Subject: cannot chanhge execute method for single HttpClient instance MIME-Version: 1.0 Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit X-Nabble-From: nicholas.hammonds@gmail.com X-Virus-Checked: Checked by ClamAV on apache.org Hi, I'm using HttpClient to talk to ruby on rails webservice. Basically after much playing about I have discovered that in order to post into the interface I need to supply an authenticity_token in the parameters of the POST. Now in order to get a valid authenticity_token I first need to do a GET on the relevant interface. The authenticity_token is only valid for a particular HttpClient session, so should be simple enough to do a GET then a post ... wrong. If I use the same HttpClient and c executrMethod with a getMethod and then a postMethod, the getMethod just gets executed twice. Here is my code, is there a way to override the getMethod so the postMethod gets done correctly many thanks HttpClient client = new HttpClient(); client.getParams().setParameter("http.useragent", "Test Client"); client.getParams().setParameter("http.connection.timeout",new Integer(5000)); String authToken = null; try { method.setURI(new URI("http://dev-integration-test.dsi.thus.net:3001/orders/new", true)); int returnCode = client.executeMethod(method); if(returnCode != HttpStatus.SC_OK) { System.err.println( "Unable to fetch default page, status code: " + returnCode); } BufferedInputStream is = new BufferedInputStream(method.getResponseBodyAsStream()); authToken = XhtmlParser.parseAuthToken(is); logger.debug("XXXXXXXXXXXXX authToken is: " + authToken ); } catch (HttpException he) { System.err.println(he); } catch (IOException ie) { System.err.println(ie); } finally { method.releaseConnection(); } client.getParams().setParameter("http.useragent", "Test Client"); BufferedReader br = null; method = new PostMethod("http://dev-integration-test.dsi.thus.net:3001/orders/new"); System.out.println("defined postmethod"); ((PostMethod)method).addParameter("authenticity_token", authToken); try{ int returnCode = client.executeMethod(method); if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) { System.err.println("The Post method is not implemented by this URI"); // still consume the response body } else { logger.debug("post response is " + method.getResponseBodyAsString()); # XXXXX this comes out the same as stream I got back from the original GET call .. -- View this message in context: http://www.nabble.com/cannot-chanhge-execute-method-for-single-HttpClient-instance-tp21932530p21932530.html Sent from the HttpClient-User mailing list archive at Nabble.com. --------------------------------------------------------------------- To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org For additional commands, e-mail: httpclient-users-help@hc.apache.org