1

I have a project on Android Studio using url to extract content. I using HttpURLConnection, create a openConnection but it not working. My code below:

try
{
    URL url = new URL("https://stackoverflow.com/questions/14825374/reading-a-textfile-using-inputstream/");
    HttpURLConnection httpcon = (HttpURLConnection) url.openConnection();
    httpcon.addRequestProperty("User-Agent", "Mozilla/4.76");
    String content = httpcon.getContentType();
    tv.setText(content);
}
catch (Exception e)
{
    tv.setText("Can't connect");
}

But when i use the same type of connection in eclipse, it's work. Is that difference between Android Studio and Eclipse? Thank you for reading.

0 Answers0