Skip to content Skip to sidebar Skip to footer

Read Text From Html Body

In my android application i'm signing up a user with username and password, if done correctly it returns value '1' if not then '0' by calling a URL with a username and password as

Solution 1:

You could try this. The String str will contain your response.

String str;
 try
        {
            HttpClientclient=newDefaultHttpClient();
            HttpPostpostalcall=newHttpPost("http://www.page.com/page.php");
            HttpResponseresponse= client.execute(postalcall);


            if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
            {
                str = EntityUtils.toString(response.getEntity());
            }
        }catch(IOException e){
            e.printStackTrace();
        }  

You can put it into a function etc

PublicStringfetchContent(String http) {
    String str;
     try
            {
                HttpClient client = newDefaultHttpClient();
                HttpPost postalcall = newHttpPost(http);
                HttpResponse response = client.execute(postalcall);


                if(response.getStatusLine().getStatusCode() == HttpStatus.SC_OK)
                {
                    str = EntityUtils.toString(response.getEntity());
                }
            }catch(IOException e){
                e.printStackTrace();
            }  
     return str;

}

and just call

Stringresponse= fetchContent("http://www.page.com/page.pgp");

Hope it helps

Post a Comment for "Read Text From Html Body"