码迷,mamicode.com
首页 > Web开发 > 详细

http调接口

时间:2016-05-18 17:26:37      阅读:134      评论:0      收藏:0      [点我收藏+]

标签:

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调接口

标签:

原文地址:http://www.cnblogs.com/lizihao/p/5505822.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!