I want to receive an xml from webservice on android

0

I've tried everything, using HttpURLConnection , with HttpClient that is deprecated, these two options do not end, they stop at BufferedReader . I've tried using AsyncTask with doInBackground , but error:

  

android.os.NetworkOnMainThreadException

I have already put the permission to access the internet. Here's what I'm trying to do.

try {
        URL url = new URL(s);            
        HttpURLConnection urlConnection = (HttpURLConnection) url.openConnection();

        try {
            BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(urlConnection.getInputStream()));                
            StringBuilder stringBuilder = new StringBuilder();                
            String line;
            while ((line = bufferedReader.readLine()) != null) {
                stringBuilder.append(line).append("\n");
            }
            bufferedReader.close();
            System.out.println("----------------------"+stringBuilder.toString());
            return stringBuilder.toString();
        }
        finally{
            urlConnection.disconnect();
        }
    }
    catch(Exception e) {
        Log.e("ERROR", e.getMessage(), e);
        return null;
    }
    
asked by anonymous 26.10.2016 / 19:11

0 answers