'volley post request issue
I'm not an Android / Java developer but I need to fix this problem in an open source project.
I encountered the error "E / Volley: [300] BasicNetwork.performRequest" while submitting the request and no further explanation was given for this error.
btnSubmit.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View view) {
String URL ="http://someURL/api/crm/check_login";
Response.Listener<String> listener = new Response.Listener<String>() {
@Override
public void onResponse(String response) {
// LOG Response Or ...
}
};
StringRequest request = new StringRequest(Request.Method.POST, URL, listener, errorListener)
{
@Override
protected Map<String, String> getParams() throws AuthFailureError {
Map<String, String> params = new HashMap<>();
params.put("username","TEST");
params.put("password","123456");
return params;
}
};
AppController.getInstance().addToRequestQueue(request);
});
}
Solution 1:[1]
You need to add Content-Type to the header.
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json; charset=utf-8");
return headers;
}
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Xay |
