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(); }