返回顶部

收藏

通过 HttpClient从指定server获取数据

更多
DefaultHttpClient httpClient = new DefaultHttpClient();
            HttpGet method = new HttpGet(“[u]http://www.baidu.com/1.html[/u]”);
            HttpResponse resp;
            Reader reader = null;
            try {
                // AllClientPNames.TIMEOUT
                HttpParams params = new BasicHttpParams();
                params.setIntParameter(AllClientPNames.CONNECTION_TIMEOUT, 10000);
                httpClient.setParams(params);
                resp = httpClient.execute(method);
                int status = resp.getStatusLine().getStatusCode();
           if (status != HttpStatus.SC_OK) return false;
               // HttpStatus.SC_OK;
                return true;
            } catch (ClientProtocolException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } catch (IOException e) {
                // TODO Auto-generated catch block
                e.printStackTrace();
            } finally {
                if (reader != null) try {
                    reader.close();
                } catch (IOException e) {
                    // TODO Auto-generated catch block
                    e.printStackTrace();
                }
            }

标签:HttpClient,Server数据,Android

收藏

0人收藏

支持

0

反对

0