You are viewing a plain text version of this content. The canonical link for it is here.
Posted to httpclient-users@hc.apache.org by Mohit Anchlia <mo...@gmail.com> on 2011/07/20 23:02:24 UTC

Hangs on DefaultHttpClient

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


Re: Hangs on DefaultHttpClient

Posted by Mohit Anchlia <mo...@gmail.com>.
I upgraded and it worked.

On Wed, Jul 20, 2011 at 2:02 PM, Mohit Anchlia <mo...@gmail.com> wrote:
> 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