一尘不染

使用eclipse从android读取php页面内容

java

请我想一个非常简单的方法来从我的android应用程序读取我的php页面的内容!我不需要jSon之类的东西,我想要的就是让php页面的内容在Java中成为String!预先谢谢你!


阅读 225

收藏
2020-12-03

共1个答案

一尘不染

HttpClient client = new DefaultHttpClient();
HttpGet request = new HttpGet(url);
HttpResponse response = client.execute(request);

    String html = "";
    InputStream in = response.getEntity().getContent();
    BufferedReader reader = new BufferedReader(new InputStreamReader(in));
    StringBuilder str = new StringBuilder();
    String line = null;
    while((line = reader.readLine()) != null)
    {
        str.append(line);
    }
    in.close();
    html = str.toString();



   Log.i('HtmlContent',+html)
2020-12-03