标签:
private static String doGetResult(String urlStr, Map<String, String> params)
throws Exception {
System.out.println(urlStr);
PostMethod postMethod = new PostMethod(urlStr);
try {
postMethod.addParameter("info",
URLEncoder.encode(Map2JSON(params), UTF8));
HttpClient client = new HttpClient();
postMethod.getParams().setParameter(
HttpMethodParams.HTTP_CONTENT_CHARSET, UTF8);// 对含有中文的字符进行编码
client.setConnectionTimeout(1000 * 60); // 设置超时时间 1分钟
int status = 0;
status = client.executeMethod(postMethod);
if (status != 200) {// 连接失败
// System.out.println("responseMsg:服务器内部错误!!!");
throw new Exception("服务器内部错误!!!");
}
byte[] responseBody = postMethod.getResponseBody();
return new String(responseBody);
} catch (Exception e) {
e.printStackTrace();
throw new Exception(e);
} finally {
// 6.释放连接
postMethod.releaseConnection();
}
}
标签:
原文地址:http://www.cnblogs.com/lizihao/p/5505822.html