Android的REST客户端客户端、Android、REST

2023-09-05 09:39:31 作者:到頭來只是夢一場

我发现这么多的样本请求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.