简体   繁体   中英

How to pass edittext value from android to java RESTFUL webservice url

I'm very new to Android, I'm using a Java RESTful webservice for login purposes..

Webservice url:
http://localhost:8084/TestWebApp/webresources/userbay/signin?mobile=username&code=password

Here username and password are from Edittext values from Android.

My question is, how to pass the EditText value from Android to that webservice URL, and how to get the response from the webservice store to an Android variable.

My code:

 public void btnClick(View v) { username = (EditText) findViewById(R.id.signin_mobile); password = (EditText) findViewById(R.id.signin_password); String usrname = username.getText().toString(); String usrpassword = password.getText().toString(); if (usrname.equals("") || usrpassword.equals("") ) { Toast.makeText(getApplicationContext(), "Field cannot be left blank.", Toast.LENGTH_SHORT).show(); } else { webservice(); } } 

I don't know how to start to connect to the webservice.. a code sample would be most helpful for me..

I would recommend you to use Spring for Android in you Android project.

Spring offers RestTemplate that allows you to send HTTP requests to RESTful services and retrieve result data. Both request and response can be transported in JSON format. With RestTemplate you just send and retrieve Java object.

You can learn more here: http://projects.spring.io/spring-android/

I would recommend you to use Volley . Some time ago, the Google+ team did a series of performance tests on each of the different methods you can use to make network requests on Android. Volley got a score up to ten times better than the other alternatives when used in RESTful applications.

Volley is a networking library developed by Google and introduced during Google I/O 2013.

Searching on Google you'll find a lot of examples on how to use:

Example 1

Example 2

Example 3

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM