hc-httpclient-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Mohit Anchlia <mohitanch...@gmail.com>
Subject Re: Hangs on DefaultHttpClient
Date Wed, 20 Jul 2011 23:01:38 GMT
I upgraded and it worked.

On Wed, Jul 20, 2011 at 2:02 PM, Mohit Anchlia <mohitanchlia@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


Mime
View raw message