public static String doJsonPost(String url, JSONObject params)
throws ClientProtocolException, IOException {
HttpClient httpclient = HttpClients.createDefault();
//毫秒
RequestConfig requestConfig = RequestConfig.custom()
.setConnectTimeout(5000000).setConnectionRequestTimeout(1000000)
.setSocketTimeout(5000000).build();
// HttpClient.getHttpConnectionManager().getParams().setConnectionTimeout(5000);
HttpPost httpPost = new HttpPost(url);
httpPost.setConfig(requestConfig);
httpPost.setHeader("User-Agent",
"Mozilla/5.0 (Windows NT 6.1; rv:6.0.2) Gecko/20100101 Firefox/6.0.2");
StringEntity entity = new StringEntity(params.toString(), "utf-8");// 解决中文乱码问题
entity.setContentEncoding("UTF-8");
entity.setContentType("application/json");
httpPost.setEntity(entity);
return httpclient.execute(httpPost, new MyResponseHandler<Object>())
.toString();
}
这是我的工具类 但是在本地的话就可以吧数据传到第三方 我部署到服务器怎么就网络超时啊