hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohit Anchlia <mohitanch...@gmail.com>
Subject Hangs on DefaultHttpClient
Date Wed, 20 Jul 2011 21:02:24 GMT
I am using 4.0 and have this code. I think I am doing something wrong
but not sure what. My program hangs when executing new
DefaultHttpClient()

On server side I use request.getParameter() that I set using setEntity.

   public static boolean doPost(String uri, Map<String,String> attrib){

	   boolean result=false;
       HttpClient httpclient = new DefaultHttpClient();
       System.out.println("Here 1");

       HttpPost httppost = new HttpPost(uri);
       System.out.println("Here 2");

       List pairs = new ArrayList();
       System.out.println("Here 1");
       for (String s : attrib.keySet()){    	
    	   pairs.add(new BasicNameValuePair(s, attrib.get(s)));
       }

       try {
		httppost.setEntity(new UrlEncodedFormEntity(pairs));
		HttpResponse response = httpclient.execute(httppost);
		if (200 != response.getStatusLine().getStatusCode()){
			log.info("Error " + response.getStatusLine().getReasonPhrase() + "
" + response.getStatusLine().getStatusCode());
			result=false;
		}
	} catch (ClientProtocolException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	} catch (IOException e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}finally{
		httpclient.getConnectionManager().shutdown();
	}	
	return result;
   }

---------------------------------------------------------------------
To unsubscribe, e-mail: httpclient-users-unsubscribe@hc.apache.org
For additional commands, e-mail: httpclient-users-help@hc.apache.org


Mime
View raw message