Android的 - 阅读与HTTP GET XML文件 [英] Android - Read an XML file with HTTP GET

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

问题描述

我需要探索在Android上我的项目中使用的Web服务。我知道,有对XML没有正式的图书馆 - RPC Web服务

但对于REST XML和我需要对其进行测试。

我想读取XML在我的网页(在那里我有通过用户名和密码)从Android的使用HTTP GET。

假设,我按照 此链接 ,然后我在哪里过的用户名和密码?

任何人可以帮助我在此。

解决方案

  HTTPGET URI =新HTTPGET(http://example.com);

DefaultHttpClient客户端=新DefaultHttpClient();
HTT presponse RESP = client.execute(URI);

状态行状态= resp.getStatusLine();
如果(status.getStatus code()!= 200){
    Log.d(标签,HTTP错误,无效的服务器状态code:+ resp.getStatusLine());
}

DocumentBuilderFactory的工厂= DocumentBuilderFactory.newInstance();
DocumentBuilder的建设者= factory.newDocumentBuilder();
文档DOC = builder.parse(resp.getEntity()的getContent());
 

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.

解决方案

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天全站免登陆