HttpClient get 方法传递json参数的问题
public static String httpGet(String url, String token) {
HttpClient hc = new DefaultHttpClient();
String body = null;
try {
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("token", token);
HttpResponse response = hc.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
body = EntityUtils.toString(entity, "utf-8");
}
} catch (ParseException e) {
System.out.println(e.getMessage());
body = "1";
} catch (UnsupportedEncodingException e) {
System.out.println(e.getMessage());
body = "2";
} catch (ClientProtocolException e) {
System.out.println(e.getMessage());
body = "3";
} catch (IOException e) {
System.out.println(e.getMessage());
body = "4";
}
return body;
}
String url = "http://www.xx.com";
String param = "{\"appId\":\"11111\",\"secrectKey\":\"11111\",\"userName\":\"3333\"}";
String token="asdasf";
如何传递json参数,求大神指点
HttpClient hc = new DefaultHttpClient();
String body = null;
try {
HttpGet httpGet = new HttpGet(url);
httpGet.setHeader("token", token);
HttpResponse response = hc.execute(httpGet);
HttpEntity entity = response.getEntity();
if (entity != null) {
body = EntityUtils.toString(entity, "utf-8");
}
} catch (ParseException e) {
System.out.println(e.getMessage());
body = "1";
} catch (UnsupportedEncodingException e) {
System.out.println(e.getMessage());
body = "2";
} catch (ClientProtocolException e) {
System.out.println(e.getMessage());
body = "3";
} catch (IOException e) {
System.out.println(e.getMessage());
body = "4";
}
return body;
}
String url = "http://www.xx.com";
String param = "{\"appId\":\"11111\",\"secrectKey\":\"11111\",\"userName\":\"3333\"}";
String token="asdasf";
如何传递json参数,求大神指点
...全文
相关推荐
WebApi系列-通过HttpClient来调用WebApi接口.doc
WebApi系列-通过HttpClient来调用WebApi接口.doc
Java调用第三方接口示范的实现
主要介绍了Java调用第三方接口示范的实现,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
HttpClient所需jar包,包含JSONObject依赖的jar。全包
HttpClient所需jar包,包含JSONObject依赖的jar。搭建httpclient环境所需的所有jar包,不用再下载别的jar。
HttpClientUtils
一款基于HttpClient的工具类。 可二次开发 ,目前已集成文件上传 参数传递 Json传输 请求头添加等功能
Titanium中Httpclient访问REST 服务
NULL 博文链接:https://topmanopensource.iteye.com/blog/1455044


Web 开发
