Saturday, 15 March 2014

java - How to communicate to a RESTful Webservice in Android Client -


I have developed a privilege webservice using (Java + Jersey) ... service to communicate with users requires that the user is required to fill a form in Android client app and it will be sent back to the webservice service, where it will be processed in accordance with the user will get the output ...

when I For the first time the rest of the webservice was created Webclient ... And so "post" and was able to send and receive requests in the form of parameters, such as "get" ...

But how do Android is because there is no form tag Attributes such as method = "post"

have been instructed to use XML parsing.

updated: I know how to connect and receive data in Android

  @ Path ( "/ user") @ POST @ Products ({MediaType.TEXT_HTML, MediaType is .APPLICATION_XML}) @Consumes (MediaType.APPLICATION_FORM_URLENCODED) public void new user (@FormP Syria ( "uname") string Anam, @ Formmaram ( "password") string password @ Conteks Actiteepisrwlet Response servlet response) throws IOException {boolean unamec = UserLogin.checkuname (uname); If (unamec) {// user already exists servletResponse.sendRedirect ("http: //mysite/Login.html"); } And {User Login U = New User Login (Ecadem, Password); ServletResponse.sendRedirec ("http: // mysite / users /" + uname + "/ createnewshop"); }}    

I have seen that you have used the POST methods Here's a snippet that can help you.

  string urlParameters = "param_a = a and param_b = b"; Url url = new url ("http://www.yourwebservice.com"); HttpURL Connection Connection = (HttpURL Connection) url.openConnection (); Connection.setDoOutput (true); Connection.setDoInput (true); Connection.setInstanceFollowRedirects (wrong); Connection.setRequestMethod ("post"); Connection.setRequestProperty ("content-type", "app / x-www-form-url expired"); Connection.setRequestProperty ("charset", "UTF-8"); Connection.setRequestProperty ("content-length", "" + integer .stosting (urlParameters.getBytes (length)); connection.setUseCaches (wrong); // Web service outputTreamWitter author = new outputoutwitter (connection.getOutputStream () ) Writes content; writer.write (urlParameters); writer.flush (); writer.close (); // reads the answer from the web service BufferedReader = new BufferedReader (New InputStreamReader (connection.getInputStream ()); string decoded string; while ((decoded string = in.readLine ())! = nULL) {returnMsg + = decodedString;} In.close (); connection.disconnect ();   

I Only you Suggest that you join your Android app in this way by guaranteeing your Android app to work in all Android.

No comments:

Post a Comment