Rohit gupta :
MY AIM: HOW TO REQUEST IN RAW FORMAT WITH POST REQUEST AND CONTENT-TYPE:APPLICATION/JSON IN JAVA
This is my POSTMAN Request Header content-type: application/json Method: POST
I am getting this response which is CORRECT but same thing when I try with android java it gives error
ANDROID CODE:
private void login(String email, String password) {
RequestQueue MyRequestQueue = Volley.newRequestQueue(this);
String url = "https://www.********.in/login.php";
StringRequest MyStringRequest = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Toast.makeText(LoginActivity.this, response, Toast.LENGTH_SHORT).show();
}
}, new Response.ErrorListener() { //Create an error listener to handle errors appropriately.
@Override
public void onErrorResponse(VolleyError error) {
//This code is executed if there is an error.
}
}) {
protected Map<String, String> getParams() {
Map<String, String> MyData = new HashMap<String, String>();
MyData.put("email", email);
MyData.put("password", password);
return MyData;
}
};
MyRequestQueue.add(MyStringRequest);
}
I'm getting this response in ANDROID as TOAST {"error":true,"message":"Invalid Credentials"} which comes only when I have written wrong password like this
PS:I have checked value of email and password by toasting it is correct
Shubham Kumar Gupta Ggps :
I have faced this error once , It was due to cachable property of JSON Volley simply try to add these lines:
MyRequestQueue.getCache().clear();
MyStringRequest.setShouldCache(false);
Guess you like
Origin http://43.154.161.224:23101/article/api/json?id=357301&siteId=1