Get text from a URL using Android HttpURLConnection

mahdi azarm

how can i get the content of the URLbelow using HttpURLConnection and put it in a TextView?

http://ephemeraltech.com/demo/android_tutorial20.php

Deepak Goyal
class GetData extends AsyncTask<String, Void, String> {

    @Override
    protected String doInBackground(String... params) {
        HttpURLConnection urlConnection = null;
        String result = "";
        try {
            URL url = new URL("http://ephemeraltech.com/demo/android_tutorial20.php");
            urlConnection = (HttpURLConnection) url.openConnection();

            int code = urlConnection.getResponseCode();

            if(code==200){
                InputStream in = new BufferedInputStream(urlConnection.getInputStream());
                if (in != null) {
                    BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(in));
                    String line = "";

                    while ((line = bufferedReader.readLine()) != null)
                        result += line;
                }
                in.close();
            }

            return result;
        } catch (MalformedURLException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        }

        finally {
            urlConnection.disconnect();
        }
        return result;

    }

    @Override
    protected void onPostExecute(String result) {
        yourTextView.setText(result);
        super.onPostExecute(s);
    }
}

and call this class by using

new GetData().execute();

Collected from the Internet

Please contact [email protected] to delete if infringement.

edited at
0

Comments

0 comments
Login to comment

Related

From Dev

Get JSON object from URL using HTTPURLConnection on android

From Dev

Getting xml from url with HttpURLConnection in Android

From Dev

ANDROID - How to get return success from web service in android using httpurlconnection?

From Dev

Android HttpUrlconnection not posting to URL

From Dev

NullPointerException when trying to read info from an url using HttpURLConnection

From Dev

Jquery - detect and get the url from text using jquery

From Dev

httpurlconnection unable to connect to url in android

From Dev

How to get text from url

From Dev

Get text from a <p> with specific id in Android using Jsoup

From Dev

How to get java objects from JSONArray url using Jackson in Android

From Dev

Digest authentication in Android using HttpURLConnection

From Dev

Android POST request using HttpURLConnection

From Dev

Android POST request using HttpURLConnection

From Dev

Login Screen using httpurlconnection android

From Dev

Android HttpUrlConnection Url doesn't work on emulator

From Dev

Android HttpUrlConnection Url doesn't work on emulator

From Dev

How to get the Edit text position from Recycler View adapter using Text Watcher in android

From Dev

How to get direct link of remote video from embedded url within a url in Android using JSoup?

From Dev

Android HttpUrlConnection does POST instead of GET

From Dev

Android HttpUrlConnection does POST instead of GET

From Dev

Get webpage text from URL after authorization

From Dev

How to get certain text from a url links

From Dev

get text from url list to csv

From Dev

Is it possible to load an URL using Text View in Android?

From Dev

PHP Get Values from a URL using GET[]

From Dev

How to replace text with an image from a url in Android?

From Dev

eclipse android load text from url

From Dev

Extract complete url from a text in android

From Dev

Android to Php server communicaton using HttpURLConnection

Related Related

  1. 1

    Get JSON object from URL using HTTPURLConnection on android

  2. 2

    Getting xml from url with HttpURLConnection in Android

  3. 3

    ANDROID - How to get return success from web service in android using httpurlconnection?

  4. 4

    Android HttpUrlconnection not posting to URL

  5. 5

    NullPointerException when trying to read info from an url using HttpURLConnection

  6. 6

    Jquery - detect and get the url from text using jquery

  7. 7

    httpurlconnection unable to connect to url in android

  8. 8

    How to get text from url

  9. 9

    Get text from a <p> with specific id in Android using Jsoup

  10. 10

    How to get java objects from JSONArray url using Jackson in Android

  11. 11

    Digest authentication in Android using HttpURLConnection

  12. 12

    Android POST request using HttpURLConnection

  13. 13

    Android POST request using HttpURLConnection

  14. 14

    Login Screen using httpurlconnection android

  15. 15

    Android HttpUrlConnection Url doesn't work on emulator

  16. 16

    Android HttpUrlConnection Url doesn't work on emulator

  17. 17

    How to get the Edit text position from Recycler View adapter using Text Watcher in android

  18. 18

    How to get direct link of remote video from embedded url within a url in Android using JSoup?

  19. 19

    Android HttpUrlConnection does POST instead of GET

  20. 20

    Android HttpUrlConnection does POST instead of GET

  21. 21

    Get webpage text from URL after authorization

  22. 22

    How to get certain text from a url links

  23. 23

    get text from url list to csv

  24. 24

    Is it possible to load an URL using Text View in Android?

  25. 25

    PHP Get Values from a URL using GET[]

  26. 26

    How to replace text with an image from a url in Android?

  27. 27

    eclipse android load text from url

  28. 28

    Extract complete url from a text in android

  29. 29

    Android to Php server communicaton using HttpURLConnection

HotTag

Archive