如何从Android的使用Android的ADT日食叫休息web服务? [英] How to call Rest webService from android with using android adt eclipse?

查看:136
本文介绍了如何从Android的使用Android的ADT日食叫休息web服务?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何调用Android的从一个web服务?我是新到Android,任何一个可以发一些链接,怎么做或任何教程如何从从头开始。

How to call a webservice from android ? I am new to android,any one can send some link,how to do or any tutorial how to start from the scratch.

我想用restwebservice了一个Android ADT日食,并告诉我如何与现有的网站使用?

I want to use restwebservice for an android adt eclipse,and tell me how to use with the existing website ?

点击该按钮后,它表明网站,如何使用http那一个呢?但在HTTP其只显示字符串

推荐答案

首先添加下列内容清单。这是为了请求访问互联网的权限。

Firstly add following to your manifest. This is to request for a permission to access the internet.

<uses-permission android:name="android.permission.INTERNET" />

然后打一个Web服务最简单的方法是使用的HttpClient 与Android捆绑的:

Then the simplest way to hit a webservice is use the HttpClient bundled with android:

HttpClient httpclient = new DefaultHttpClient();
HttpResponse response = httpclient.execute(new HttpGet(URL));
StatusLine statusLine = response.getStatusLine();
if(statusLine.getStatusCode() == HttpStatus.SC_OK){
    ByteArrayOutputStream out = new ByteArrayOutputStream();
    response.getEntity().writeTo(out);
    out.close();
    String responseString = out.toString();
    //Whatever you wanna do with the response
} else{
    //Close the connection.
    response.getEntity().getContent().close();
    throw new IOException(statusLine.getReasonPhrase());
}

这篇关于如何从Android的使用Android的ADT日食叫休息web服务?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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