hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From caffeine zombie <nicholas.hammo...@gmail.com>
Subject cannot chanhge execute method for single HttpClient instance
Date Tue, 10 Feb 2009 12:25:15 GMT

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");

String authToken = null;
	    try {

URI("http://dev-integration-test.dsi.thus.net:3001/orders/new", true));
	      int returnCode = client.executeMethod(method);

	      if(returnCode != HttpStatus.SC_OK) {
	          "Unable to fetch default page, status code: " + returnCode);
	      BufferedInputStream is = new
	      authToken = XhtmlParser.parseAuthToken(is);
	      logger.debug("XXXXXXXXXXXXX authToken is: " + authToken );

	    } catch (HttpException he) {
	    } catch (IOException ie) {
	    } finally {

client.getParams().setParameter("http.useragent", "Test Client");

	    BufferedReader br = null;

	    method = new
	    System.out.println("defined postmethod");
	    ((PostMethod)method).addParameter("authenticity_token", authToken);
	      int returnCode = client.executeMethod(method);
	      if(returnCode == HttpStatus.SC_NOT_IMPLEMENTED) {
	        System.err.println("The Post method is not implemented by this
	        // 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

View raw message