现在的位置: 首页 > 综合 > 正文

服务端

2013年05月25日 ⁄ 综合 ⁄ 共 577字 ⁄ 字号 评论关闭

客户端向服务器请求获取请求结果示例代码:

  1. public String getRseponse(String url) {
  2.         HttpClient httpClient = new DefaultHttpClient();        
  3.         HttpGet httpGet = new HttpGet(url);
  4.         HttpResponse httpResponse;
  5.         try {
  6.             httpResponse = httpClient.execute(httpGet);
  7.             HttpEntity entity = httpResponse.getEntity();
  8.             if (entity != null) {
  9.                 InputStream inputStream = entity.getContent();
  10.                 String jsonString = convertStreamToString(inputStream);
  11.                 return jsonString;
  12.             }
  13.         } catch (ClientProtocolException e) {
  14.             e.printStackTrace();
  15.         } catch (IOException e) {
  16.             e.printStackTrace();
  17.         }
  18.         return null;
  19.     }

抱歉!评论已关闭.