Android - 使用 HTTP GET 读取 XML 文件 [英] Android - Read an XML file with HTTP GET

查看:29
本文介绍了Android - 使用 HTTP GET 读取 XML 文件的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要探索我的项目在 Android 上使用网络服务.我知道没有用于 XML - RPC Web 服务的官方库.

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.

但是有 REST XML,我需要测试它.

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

我想使用 HTTP GET 从 Android 读取我的网页上的 XML(我必须在其中传递用户名和密码).

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

假设,我按照 此链接,那么我在哪里传递用户名和密码?

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

谁能帮我解决这个问题.

Can anybody help me on this.

推荐答案

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());

这篇关于Android - 使用 HTTP GET 读取 XML 文件的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆