How to get content of a URL and to read it in a android java application using eclipse

后端 未结 1 990
栀梦
栀梦 2021-01-01 06:18

//Following code works fine but read\'s the source code as well as the content, I just need to read the content Thanks for the help.//

package t.n.e;

import         


        
相关标签:
1条回答
  • 2021-01-01 07:09

    Well, if you just need the content, why won't you simplify it this way:

        private InputStream OpenHttpConnection(String strURL)
                throws IOException {
            URLConnection conn = null;
            InputStream inputStream = null;
            URL url = new URL(strURL);
            conn = url.openConnection();
            HttpURLConnection httpConn = (HttpURLConnection) conn;
            httpConn.setRequestMethod("GET");
            httpConn.connect();
            if (httpConn.getResponseCode() == HttpURLConnection.HTTP_OK) {
                inputStream = httpConn.getInputStream();
            }
            return inputStream;
        }
    

    And then just read the stream?

    0 讨论(0)
提交回复
热议问题