当前位置: 代码迷 >> 综合 >> 微信API调用post
  详细解决方案

微信API调用post

热度:50   发布时间:2024-02-02 07:40:23.0
public static JSONObject wxdoPost(String url, JSONObject jsonData) {// 指定Post请求HttpPost httpPost = new HttpPost(url);// 创建httpclientHttpClient httpClient = new DefaultHttpClient();// 发送请求org.apache.http.HttpResponse httpResponse;// 返回的jsonJSONObject 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");// 返回jsonjsonObject=JSONObject.fromObject(str);}} catch (ClientProtocolException e) {// TODO Auto-generated catch blocke.printStackTrace();} catch (IOException e) {// TODO Auto-generated catch blocke.printStackTrace();}return jsonObject;
}
  相关解决方案