public static JSONObject wxdoPost(String url, JSONObject jsonData) { // 指定Post请求 HttpPost httpPost = new HttpPost(url); // 创建httpclient HttpClient httpClient = new DefaultHttpClient(); // 发送请求 org.apache.http.HttpResponse httpResponse; // 返回的json JSONObject jsonObject = null; // 封装post请求数据 StringEntity entity = new StringEntity(jsonData.toString(), "utf-8"); httpPost.setEntity(entity); try { // 发送请求 httpResponse = httpClient.execute(httpPost); // 判断请求是否成功 if(httpResponse.getStatusLine().getStatusCode()==HttpStatus.SC_OK){ // 得到请求响应信息 String str = EntityUtils.toString(httpResponse.getEntity(), "utf-8"); // 返回json jsonObject=JSONObject.fromObject(str); } } catch (ClientProtocolException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } return jsonObject; }
微信API调用post
最新推荐文章于 2024-08-23 20:27:48 发布