In volley library giving com.android.volley.ServerError

后端 未结 6 1494
死守一世寂寞
死守一世寂寞 2021-02-09 05:30

I try to login in my application, when I try to call API using volley library, it\'s giving com.android.volley.ServerError and response code 400.

final String u         


        
相关标签:
6条回答
  • 2021-02-09 05:54

    I had the same issue. It drained my entire day. Finally, I Found the tiny error, which was that I was passing a null value in parameters.

    Check if you are passing a null value to the server in getParams() or your JSON Object. If yes, that may be the problem.

    0 讨论(0)
  • 2021-02-09 05:57

    In below method

    public void onErrorResponse(VolleyError error)
    

    add this line:-

    error.printStackTrace()
    

    You will get all stack trace which gives you the actual error. I have also get this error but in my case it is actually TimeoutException.

    0 讨论(0)
  • 2021-02-09 05:57

    This error can mean BAD REQUEST, check the headers you are sending. Overring the getHeaders() method you can send the right headers.

    @Override
    public Map<String, String> getHeaders() throws AuthFailureError {
            return (headers != null || headers.isEmpty()) ? headers : super.getHeaders();
        }
    

    Also, usually the WebServices need application/json headers, as follow:

    headers.put("Accept","application/json");
    headers.put("Content-Type","application/json");
    
    0 讨论(0)
  • 2021-02-09 06:00

    Response Code 400 means Bad Request.

    Some reasons for that.

    1. There might be issue in Request method. Is it GET or POST.
    2. API might be expecting Authorization Header.
    0 讨论(0)
  • 2021-02-09 06:00

    What causes this error... 1.Wrong Url,check your url for any errors. 2.Missing parameters,any parameters is having null value or you are missing any parameter. 3.Watch for the Keys defined in the params,it should match with those of APIs. Hope it helps!

    0 讨论(0)
  • 2021-02-09 06:02

    You have to have a same Method in your java codes and in the php codes . you defined "POST" method for your request with volley library to server , now you have to have "POST" method in your php files at your server for giving the request .

    0 讨论(0)
提交回复
热议问题