So today I was trying to use a post methode on an iis rest service in order to implement a login function in an Android-App. This rest service is protected by OAuth, so my main goal was to get the users access token.
But unfortunately my methode kept returning err 400, so i looked it up and found some solutions which didn't work in my case though.
Here's the methode:
public boolean validateUser(final String username, final String password)
{
String url="not allowed to show the url here";
final boolean[] validUser = {false};
StringRequest jsonObjRequest = new StringRequest(Request.Method.POST, url,
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject obj = new JSONObject(response);
//String token=obj.getString("token");
} catch (JSONException e) {
System.out.println("couldn't parse string to jsonObject");
}
Log.d("RESPONSE",response);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.d("volley", "Error: " + error.getMessage());
error.printStackTrace();
}
}) {
@Override
public String getBodyContentType() {
return "application/x-www-form-urlencoded"; //tried a couple of things like "application/json" and "application/x-www-form-urlencoded, encoding UTF-8"
}
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
params.put("username", username.trim());
params.put("password", password.trim());
params.put("grant_type", "password");
return params;
}
/* @Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
return headers;
}*/
};
RequestQueue requestQueue= Volley.newRequestQueue(this);
requestQueue.add(jsonObjRequest);
requestQueue.start();
//AppController.getInstance().addToRequestQueue(jsonObjRequest);
return validUser[0];
}
and the error msg i am getting:
E/Volley: [176] BasicNetwork.performRequest: Unexpected response code 400 for "not allowed to show the url"
I would appreciate any help, cheers!