HttpClient get 方法传递json参数的问题

ruanjian123456123 ruanjian123456123 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区
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参数,求大神指点
...全文
评论 2
收藏 已收藏
分享
返回顶部
ruanjian123456123
Web 开发 81,107 成员 341,720 内容