How to make a POST request from inside a Restlet
I'm curr开发者_StackOverflow中文版ent using Restlet to interface with an Android app.
I want the Restlet on the server to then trigger a C2DM push message when it gets a certain POST from an Android app - it's basically just a simple HTTP POST to Google's servers with some extra values in it.
I imagine there must be some way of using the in built connector, or otherwise, anyone have any ideas? Can't seem to find anything about it on the net, an unusual request perhaps.
Edit: Probably should have expanded on this to begin with, the reason why I ask is that I'm trying to use Apache httpClient inside the restlet but I'm not able to to get it to work. If that is what you're supposed to do, then it's probably a different question altogether.
Use Java's native HttpURLConnection object: http://download.oracle.com/javase/7/docs/api/java/net/HttpURLConnection.html
Follow the implementation guidelines provided by Google: http://code.google.com/android/c2dm/#push
So what I was doing is the right way to do it after all, I've got Apache HttpClient set up and working in a seperate thread to do the push. For some reason it fails due to a peer exception (which is the exception I was getting initially), but I've got around that by automatically trusting the SSL certificate. Why that was happening with the C2DM address I really have no idea.
精彩评论