Volley kullanımı android
Merhabalar androidden volley kullaranarak web apiye post request gondermeye çalısıyorum ancak hata alıyorum web apiden 400 dönuyor
private void doLoginUseToVolley(final String userName, final String password) {
final String url = UrlConfig.denemevolley;
RequestQueue queue = Volley.newRequestQueue(LoginActivity.this);
StringRequest sr = new StringRequest(Request.Method.POST, url, new Response.Listener<String>() {
@Override
public void onResponse(String response) {
Log.e("onResponse",response);
Toast.makeText(getApplicationContext(),response, Toast.LENGTH_LONG).show();
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
// error
Log.e("onErrorResponse",error.getMessage());
Toast.makeText(getApplicationContext(),error.getMessage(), Toast.LENGTH_LONG).show();
}
}) {
@Override
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("UserName", userName);
params.put("Password", password);
Log.e("paramsBody", params.toString());
return params;
}
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
Map<String, String> params = new HashMap<String, String>();
// Removed this line if you dont need it or Use application/json
params.put("Content-Type", "text/json; charset=utf-8");
params.put("Authorization-Token", Constants.API_KEY);
Log.e("paramsHeader", params.toString());
return params;
}
};
int socketTimeout = 30000;//30 seconds - change to what you want
RetryPolicy policy = new DefaultRetryPolicy(socketTimeout, DefaultRetryPolicy.DEFAULT_MAX_RETRIES, DefaultRetryPolicy.DEFAULT_BACKOFF_MULT);
sr.setRetryPolicy(policy);
queue.add(sr);
}
E/Volley: [62693] BasicNetwork.performRequest: Unexpected response code 400 for http://xxxxxx//api/DomMobileLogon/Post
D/AndroidRuntime: Shutting down VM
E/AndroidRuntime: FATAL EXCEPTION: main
java.lang.NullPointerException: println needs a message
at android.util.Log.println_native(Native Method)
at android.util.Log.e(Log.java:232)
at com.android.volley.Request.deliverError(Request.java:564)
at com.android.volley.ExecutorDelivery$ResponseDeliveryRunnable.run(ExecutorDelivery.java:101)
at android.os.Handler.handleCallback(Handler.java:739)
at android.os.Handler.dispatchMessage(Handler.java:95)
at android.os.Looper.loop(Looper.java:135)
at android.app.ActivityThread.main(ActivityThread.java:5274)
at java.lang.reflect.Method.invoke(Native Method)
at java.lang.reflect.Method.invoke(Method.java:372)
at com.android.internal.os.ZygoteInit$MethodAndArgsCaller.run(ZygoteInit.java:909)
at com.android.internal.os.ZygoteInit.main(ZygoteInit.java:704)
I/Process: Sending signal. PID: 21820 SIG: 9
Disconnected from the target VM, address: 'localhost:8602', transport: 'socket'