public static void main(String[] args) throws IOException {
JSONObject json = new JSONObject();
json.put("product_id","65346928");
String token = "12_ooJw2CNx2O2N3JIEt4D1w-Wi86JbHExyHZ5WMo4hETjLp5tZUe9GE6M2Mmi0cL9QXBzrPxPhl-9j34rrHSDy8Q8DYheZ45XKddYjriDd6bsdnzfCKjrLqTv1cazsVJjB0P_LCBGVxr4idB1TSEDeABAHTS";
String url = "https://api.weixin.qq.com/product/spu/get?access_token="+token;
HttpClient httpClient = new DefaultHttpClient();
HttpPost post = new HttpPost(url);
StringEntity postingString = new StringEntity(json.toJSONString(), ContentType.APPLICATION_JSON);// json传递
post.setEntity(postingString);
post.setHeader("Content-type", "application/json");
HttpResponse response = httpClient.execute(post);
String content = EntityUtils.toString(response.getEntity());
System.out.println(content);
JSONObject jsonObject = JSONObject.parseObject(content);
System.out.println(jsonObject);
}
java代码模拟postman的raw格式进行HTTP请求
最新推荐文章于 2024-01-20 02:45:32 发布