choi choi - 2 months ago 19
Android Question

How do i Log in in a webservice using my android App?

I am trying to log in in the website through my app.
I am using volley library. I am not able to figure out how should i send the data and what exactly is the response that i will get?

the URL is

public class MainActivity extends AppCompatActivity {

private static String TAG = MainActivity.class.getSimpleName();
private Button login;

private ProgressDialog pDialog;

private EditText username;
private EditText password;

String url = "";
String Username;
String Password;

public static final String KEY_USERNAME = "txtusername";
public static final String KEY_PASSWORD = "txtPassword";

protected void onCreate(Bundle savedInstanceState) {

username = (EditText) findViewById(;
password = (EditText) findViewById(;

Username = username.getText().toString().trim();
Password = password.getText().toString().trim();

pDialog = new ProgressDialog(this);
pDialog.setMessage("Please wait...");

login = (Button) findViewById(;

login.setOnClickListener(new View.OnClickListener() {
public void onClick(View v) {
Loginnow(Username, Password);

public void Loginnow(final String username1, final String password1) {

final HashMap<String, String> params = new HashMap<String, String>();
params.put(KEY_USERNAME, username1);
params.put(KEY_PASSWORD, password1);

StringRequest stringRequest = new StringRequest(Request.Method.POST, url, new String(params), new Response.Listener<String>() {
public void onResponse(String response) {

Intent intent = new Intent(getBaseContext(), Home.class);

new Response.ErrorListener() {
public void onErrorResponse(VolleyError error) {
Toast.makeText(MainActivity.this, error.toString(), Toast.LENGTH_LONG).show();

/* {
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put(KEY_USERNAME, username1);
params.put(KEY_PASSWORD, password1);

return params;



private void showpDialog() {
if (!pDialog.isShowing());


You can use POSTMAN to hit the API url and view the response.

Login is usually a post request with the credentials in body of the app. If the credentials are in params and not body, it could be either GET or POST request.

Once you figured out the HTTP method type and where params are to be placed, you can create Volley request for that method and override getParams() or getBody() methods as required.