发起http请求raw格式

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/qq_27605885/article/details/80460463

周末加班调别人给的接口,总是他的接口报错500。

但是用postman调用,设置参数格式为raw的json格式就可以通了,自己的java代码就是不通

人家又不加班  自己百度了看看。

查到了好办法

public static String result;
public static void httpTest() throws ClientProtocolException, IOException {
String token = "R5amyr6NyXCtWdScmNiuvVwBCJztfByZDUGaE2V0NwOUheW4XYlvUusYkrViTYt584RgcyXRhjxAJZG3rFlPLg";
String url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token="
+ token;
String json = "{\"action_name\":\"QR_LIMIT_SCENE\",\"action_info\":{\"scene\":{\"scene_id\":234}}}";
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
StringEntity postingString = new StringEntity(json);// json传递
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(post);
String content = EntityUtils.toString(response.getEntity());
// Log.i("test",content);
System.out.println(content);
result = content;
}
真是变态,必须要这种拼接成的json字符串,直接把map给toString就不行。
 
 

猜你喜欢

转载自blog.csdn.net/qq_27605885/article/details/80460463