Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Android - Read an XML file with HTTP GET

Tags:

android

xml

get

I need to explore for my project use of web services on Android. I know that there is no official library for XML - RPC web service.

But there is for REST XML and i need to test it.

I would like to read XML on my web page (Where i have to pass username and Password) from Android with HTTP GET.

OR

Suppose, i follow This link, then where do i pass username and password?

Can anybody help me on this.

like image 263
Paresh Mayani Avatar asked Aug 03 '10 09:08

Paresh Mayani


1 Answers

HttpGet uri = new HttpGet("http://example.com");    

DefaultHttpClient client = new DefaultHttpClient();
HttpResponse resp = client.execute(uri);

StatusLine status = resp.getStatusLine();
if (status.getStatusCode() != 200) {
    Log.d(tag, "HTTP error, invalid server status code: " + resp.getStatusLine());  
}

DocumentBuilderFactory factory = DocumentBuilderFactory.newInstance();
DocumentBuilder builder = factory.newDocumentBuilder();
Document doc = builder.parse(resp.getEntity().getContent());
like image 127
Gianni Avatar answered Oct 24 '22 10:10

Gianni