HttpClient的一些参数设置(想到线程的朋友进)

时间:2022-08-27 22:03:39

HttpClient折腾我一上午,主线程总是先执行,不等请求返回来就跑了!!!!!!!!HttpClient的一些参数设置(想到线程的朋友进)我以为整个线程等待什么的,可是没有线程接口。结果就是设置下参数。一下就搞定了。

上代码艹

             HttpClient httpclient = new HttpClient();
			  GetMethod httpget = new GetMethod(url.toString()); 
			  httpclient.getHttpConnectionManager().getParams().setConnectionTimeout(3000); 
			  httpclient.getHttpConnectionManager().getParams().setSoTimeout(2000);
			  try { 
				 httpclient.executeMethod(httpget);
//			    System.out.println(httpget.getStatusLine());
			    String jsonStr = httpget.getResponseBodyAsString();
//			    System.out.println(jsonStr);
			    JSONObject object = JSON.parseObject(jsonStr); 
//			    System.out.println(object.toString());
			    openid = object.getString("openid");
			  }catch(Exception e){
				  e.printStackTrace();
			  } finally {
			    httpget.releaseConnection();
			  }