问题描述:

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();

}

}

网友答案:

follow the link http://programmerguru.com/android-tutorial/android-restful-webservice-tutorial-how-to-call-restful-webservice-in-android-part-3/

it will help u :)

网友答案:

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

相关阅读:
Top