Saturday, November 24, 2012

Get xml from a php webservice url using android

public String getXML(){
    String line = null;
    try {
        DefaultHttpClient httpClient = new DefaultHttpClient();
        HttpGet httpPost = new HttpGet("http://example.com/a.php");

        HttpResponse httpResponse = httpClient.execute(httpPost);
        HttpEntity httpEntity = httpResponse.getEntity();
        line = EntityUtils.toString(httpEntity);
    } catch (Exception ex) {
        Log.d("Error reading xml", ex.toString());
    }
    return line;
}
 
But if u are using your local host as test purpose then use 10.0.2.2
instead of localhost/127.0.0.1  

No comments:

Post a Comment