Exemple #1
0
 /**
  * 执行GET请求 thinkpad dushaofei
  *
  * @param get
  * @return
  * @throws ClientProtocolException
  * @throws IOException
  */
 public static JSONObject getJsonObject(HttpGet get) throws ClientProtocolException, IOException {
   HttpClient hc = HttpClientUtils.warpClient();
   HttpResponse resp = hc.execute(get);
   HttpEntity enty = resp.getEntity();
   InputStream is = enty.getContent();
   BufferedReader br = new BufferedReader(new InputStreamReader(is));
   String backMessage = br.readLine();
   JSONObject json = JSONObject.fromObject(backMessage);
   return json;
 }
Exemple #2
0
 /**
  * 执行POST请求 thinkpad dushaofei
  *
  * @param request
  * @return
  * @throws ClientProtocolException
  * @throws IOException
  */
 public static JSONObject getJsonObject(HttpUriRequest post)
     throws ClientProtocolException, IOException {
   post.setHeader("Content-Type", "application/json;charset=UTF-8");
   HttpClient hc = HttpClientUtils.warpClient();
   HttpResponse response = hc.execute(post);
   HttpEntity Respentity = response.getEntity();
   InputStream is = Respentity.getContent();
   BufferedReader br = new BufferedReader(new InputStreamReader(is));
   String backMessage = br.readLine();
   JSONObject jsonObj = JSONObject.fromObject(backMessage);
   return jsonObj;
 }