客户端向服务器请求获取请求结果示例代码:
- public String getRseponse(String url) {
- HttpClient httpClient = new DefaultHttpClient();
- HttpGet httpGet = new HttpGet(url);
- HttpResponse httpResponse;
- try {
- httpResponse = httpClient.execute(httpGet);
- HttpEntity entity = httpResponse.getEntity();
- if (entity != null) {
- InputStream inputStream = entity.getContent();
- String jsonString = convertStreamToString(inputStream);
- return jsonString;
- }
- } catch (ClientProtocolException e) {
- e.printStackTrace();
- } catch (IOException e) {
- e.printStackTrace();
- }
- return null;
- }