首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 移动开发 > Android >

Android怎么发送Get请求

2012-08-27 
Android如何发送Get请求*URL可以随意改*/String uriAPI http://192.168.1.100:8080/test/test.jsp?uwa

Android如何发送Get请求

*URL可以随意改*/        String uriAPI = "http://192.168.1.100:8080/test/test.jsp?u=wangyi&p=456";         /*建立HTTP Get对象*/        HttpGet httpRequest = new HttpGet(uriAPI);         try         {           /*发送请求并等待响应*/          HttpResponse httpResponse = new DefaultHttpClient().execute(httpRequest);           /*若状态码为200 ok*/          if(httpResponse.getStatusLine().getStatusCode() == 200)            {             /*读*/            String strResult = EntityUtils.toString(httpResponse.getEntity());            /*去没有用的字符*/            strResult = eregi_replace("(\r\n|\r|\n|\n\r)","",strResult);            mTextView1.setText(strResult);           }           else           {             mTextView1.setText("Error Response: "+httpResponse.getStatusLine().toString());           }         }         catch (ClientProtocolException e)         {            mTextView1.setText(e.getMessage().toString());           e.printStackTrace();         }         catch (IOException e)         {            mTextView1.setText(e.getMessage().toString());           e.printStackTrace();         }         catch (Exception e)         {            mTextView1.setText(e.getMessage().toString());           e.printStackTrace();          }

热点排行