如何在android中执行GET方法?

时间:2011-09-28 13:45:44

标签: android get

我想获得这些数据---->“#1 $ Egypt $مصر@ ” 来自此链接 - > “的 http://184.173.7.132/mobile.aspx?action=4

我使用了此代码,但响应为NULL

    public HttpResponse doGet(String url) throws Exception {

    HttpResponse response = null;
    try {

        HttpClient httpclient = new DefaultHttpClient();

        HttpGet httpget = new HttpGet(url);

        response = httpclient.execute(httpget);
        }

        catch (IOException e) {
             e.printStackTrace();
        }
        return response;

} 

1 个答案:

答案 0 :(得分:2)

使用此代码,它适用于您的网址。在清单中添加互联网权限

String page;


DefaultHttpClient httpClient = new DefaultHttpClient();
                  HttpGet httpGet = new HttpGet("http://184.173.7.132/mobile.aspx?action=4");

                 // httpGet.addHeader("Content-type","application/json");


                  ResponseHandler<String> resHandler = new BasicResponseHandler();

                try
                {
                    page = httpClient.execute(httpGet, resHandler);
                } 
                catch (ClientProtocolException e) 
                {

                    e.printStackTrace();
                } catch (IOException e) {
                    // TODO Auto-generated catch block

                }
                  Log.e("response",page);