Android Rest Client

社会主义新天地 提交于 2019-11-29 00:29:01

(1) Google I/O video session for developing REST clients

(2) search in android developer blog

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

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

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

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

You probably forgot to add the internet permission to the manifest file. Add the following line.

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

I thing you should try this,

HttpContext localContext = new BasicHttpContext();
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,localContext);

Hope this will help.

By any chance, is the server expecting a GET request for this operation? If so, you may want to use HttpGet instead of HttpPost.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!