`
xp9802
  • 浏览: 1183955 次
  • 性别: Icon_minigender_1
  • 来自: 广州
社区版块
存档分类
最新评论

android通过 HttpClient 请求服务器端例子

阅读更多

      // http地址  

        String httpUrl = "http://192.168.1.110:8080/my.jsp?method=testGet";  

        //HttpGet连接对象  

        HttpGet httpRequest = new HttpGet(httpUrl);  

         //取得HttpClient对象  

            HttpClient httpclient = new DefaultHttpClient();  

            //请求HttpClient,取得HttpResponse  

            HttpResponse httpResponse = httpclient.execute(httpRequest);  

            //请求成功  

            if (httpResponse.getStatusLine().getStatusCode() == HttpStatus.SC_OK)  

            {  

                //取得返回的字符串  

                String strResult = EntityUtils.toString(httpResponse.getEntity());  

               //strResult  

            }  

            else 

            {  

               //请求失败

            }  

        } 

0
1
分享到:
评论
1 楼 酷的飞上天空 2013-12-15  
请求完成后注意释放HttpClient建立的链接

相关推荐

Global site tag (gtag.js) - Google Analytics