Android的REST客户端 [英] Android Rest Client

查看:183
本文介绍了Android的REST客户端的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我发现这么多的样本请求REST API,但所有一起是混乱的,可有人请解释我的方式来使用HTTP请求。​​

I found so many samples for requesting a REST API, but all together are confusing, can some one please explain me a way to use http requests.

我的要求是,我想通过提供用户名,PWD和一键从一个REST API的数据。

My Requirement is, I want to get data from a REST API by providing username, pwd and a key.

我已经使用了,

        HttpClient client = new DefaultHttpClient();  
        HttpPost post = new HttpPost("REST API url"); 
        post.setHeader("Content-type", "application/json");

        JSONObject obj = new JSONObject();
        obj.put("username", "un");
        obj.put("pwd", "password");
        obj.put("key","123456");

        post.setEntity(new StringEntity(obj.toString(), "UTF-8"));
        HttpResponse response = client.execute(post);

但响应总是空当与浏览器的工具,通过发布相同data.Is有些事情错了我的方法测试了这些工作的罚款?请给我建议的正确方法。谢谢

But the response is always null and these working fine when tested with browser tool by posting the same data.Is some thing wrong with my approach? please suggest me the correct way. Thank you

推荐答案

(1)谷歌I / o视频会议发展的REST客户端

(2)在Android开发者博客搜索

(2) search in android developer blog

(3) https://github.com/darko1002001/android-rest-client

后请尽量发布您的问题, 我可以从我的REST客户端共享code段开发了基于(1)及(2)

Please try after that post your question, I can share code snippet from my rest client developed based on (1) & (2)

不要使用云到设备消息,而是使用了最新的云计算方法与andrid应用程序的开发。

Do not use Cloud to Device Messaging, instead use the latest cloud approach with andrid application development.

有新的库被称为排球,它看起来比AsyncTask的更好。它应该是在开发REST风格的客户端十分有用。

There is new library called Volley, which looks better than AsyncTask. It should be useful in developing RESTful clients.

这篇关于Android的REST客户端的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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