2

{"status":"0","message":"Login unsuccessful :( This account doesn't exist or the email is not verified yet! try asking admin for activation and then logging in ;)"}

Here Is My Url

http://zeenatkhanniazai.com/services/login.php

Login class and Interface

public static String BASE_URL="http://zeenatkhanniazai.com/services/"; public static loginServices loginn=null; public static loginServices Login(){ if (loginn == null ){ Retrofit retrofit=new Retrofit.Builder().baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); loginn = retrofit.create(loginServices.class); } return loginn; } public interface loginServices{ @POST("login.php/{uemail}/{upassword}") retrofit2.Call<User> login(@Path("uemail") String uemail, @Path("upassword") String upassword); } 

MainActivity

String femail=email.getText().toString(); String fpasssword=password.getText().toString(); Call<User> call=LoginApi.Login().login(femail,fpasssword); call.enqueue(new Callback<User>() { @Override public void onResponse(Call<User> call, Response<User> response) { User users= response.body(); users.getMessege(); Toast.makeText(MainActivity.this, "respoces"+new Gson().toJson(response.body()), Toast.LENGTH_SHORT).show(); } @Override public void onFailure(Call<User> call, Throwable t) { Toast.makeText(MainActivity.this, "f", Toast.LENGTH_SHORT).show(); } 

And Here Is My User Class

@SerializedName("message") private String message; @SerializedName("status") private String status; public String getStatus() { return status; } public String message() { return message; } 
7
  • You need to use message in @SerializedName instead of messege Commented Dec 19, 2017 at 12:17
  • can you give me an example of you request URL. first be sure if it is correct. What I see is http://zeenatkhanniazai.com/services/login.php/youremail/yourpassword ; is it correct ? Commented Dec 19, 2017 at 12:19
  • it is not working Commented Dec 19, 2017 at 12:23
  • yes it is corrrect @MuratGuc Commented Dec 19, 2017 at 12:24
  • 2
    testcase : try @Field instead of @path . also try @POST("login.php") Commented Dec 19, 2017 at 12:25

1 Answer 1

4

Try this :

Api client :

public class ApiClient { public static final String BASE_URL = "http://zeenatkhanniazai.com/services/"; private static Retrofit retrofit = null; public static Retrofit getClient() { if (retrofit==null) { retrofit = new Retrofit.Builder() .baseUrl(BASE_URL) .addConverterFactory(GsonConverterFactory.create()) .build(); } return retrofit; } } 

Api interface :

public interface ApiInterface { @POST("login.php") @FormUrlEncoded Call<users> getTopRatedMovies(@Field("uemail") String uemail, @Field("upassword") String upassword); } 

User class :

public class users { @SerializedName("message") private String message; @SerializedName("status") private String status; public String getStatus() { return status; } public String getMessage() { return message; } public void setMessage(String message) { this.message = message; } public void setStatus(String status) { this.status = status; } } 

In main activity :

call.enqueue(new Callback<users>() { @Override public void onResponse(Call<users> call, Response<users> response) { progressDoalog.dismiss(); int statusCode = response.code(); String movies = response.body().getMessage(); Log.e("sdasd",movies); //Log.w("response",new Gson().toJson(response)); Log.w("response",new GsonBuilder().setPrettyPrinting().create().toJson(response)); // recyclerView.setAdapter(new MoviesAdapter(movies, R.layout.list_item_movie, getApplicationContext())); } @Override public void onFailure(Call<users> call, Throwable t) { progressDoalog.dismiss(); // Log error here since request failed Log.e(TAG, t.toString()); } }); 

Output :

Login unsuccessful :( This account doesn't exist or the email is not verified yet! try asking admin for activation and then logging in ;) 

Response :

"body": { "message": "Login unsuccessful :( This account doesn\u0027t exist or the email is not verified yet! try asking admin for activation and then logging in ;)", "status": "0" }, 
Sign up to request clarification or add additional context in comments.

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.