I have one url with request parameter is in JsonFormat like {"EmailAddress":"user@gmail.com","PassWord":"password"} it's requested parameter. When i used in POSTMAN then its okey.but when i request with program then that time i got error response. ihave tried till like this please see this snippet.
public class LoginModel {
@SerializedName("EmailAddress")
public String userName;
@SerializedName("PassWord")
public String userPass;
}
@Override
public String toString() {
Log.e("POSTLOGIN_MODEL" , userName+"||"+userPass);
return "{" +
"EmailAddress='" + userName + '\'' +
", PassWord='" + userPass + '\'' +
'}';
}
}
After that i used Interface.
public interface ApiService {
@FormUrlEncoded
@POST("/json/syncreply/AuthenticateUserRequest?")
Call<LoginResponse> LoginService(@Field("EmailAddress") String userName, @Field("PassWord") String userPass, Callback<LoginResponse> callBack);
After that i used to call this interface method through activity.
login.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
if(input_username.getText().toString() != null && input_password.getText().toString() != null
&& !input_username.getText().toString().isEmpty() && !input_password.getText().toString().isEmpty()){
LoginModel loginCredentials = new LoginModel();
loginCredentials.userName = "test@gmail.com";
loginCredentials.userPass = "password";
String request = "{\"EmailAddress\":\"raj@gmail.com\"," +
"\"PassWord\":\"pass\"}";
sendPost(loginCredentials);
}else{
Toast.makeText(getApplicationContext() , "Please enter valid Username and Password." , Toast.LENGTH_LONG).show();
}
}
});
public void sendPost(LoginModel name) {
Log.e("TAG","||"+name.userPass+"||"+name.userName);
// mAPIService.savePost(name).enqueue(new Callback<LoginModel>() {
Call<LoginResponse> call = mAPIService.LoginService(name.userName, name.userPass, new Callback<LoginResponse>() {
@Override
public void onResponse(Call<LoginResponse> call, Response<LoginResponse> response) {
Log.e("TAG" , "RESPONSE"+"||"+response.body());
}
@Override
public void onFailure(Call<LoginResponse> call, Throwable t) {
Log.e("TAG" , "FAILURE"+"||"+t.getMessage());
}
});
}
Thanks In Advance.any answer will appriciated.my english is please avoid it.