Stack Exchange
Trouble with Volley Library
I try to get response in my application, when I try to call API using volley library, it's giving com.android.volley.ServerError and response code 400.
Here is my code
RequestQueue requestQueue = Volley.newRequestQueue(this);
    try
    {
        //start bottom
        String url="http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/GetBookingDetails";
        url = url.replaceAll(" ", "%20");
        //String url="http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/Search/";
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("EndUserIp","216.10.251.69");
        jsonObject.put("TokenId","0307b931-bd7d-4860-9c4d-4d65103ebddc");
        jsonObject.put("PNR","ZERD8U");
        jsonObject.put("BookingId","1401272");
        Log.i("JsonObject",jsonObject.toString());
        JsonObjectRequest jsonobjectreq = new JsonObjectRequest(Request.Method.POST, url,jsonObject,
                new Response.Listener<JSONObject>() {
                    @Override
                    public void onResponse(JSONObject response)
                    {
                        Log.i("response",response.toString());
                        progressDialog.dismiss();
                    }
                }

It is working in postman.The error i got 
com.android.volley.ServerError

The Log is 
10-12 10:34:19.525 7149-7189/com.farehawker E/Volley: [387] BasicNetwork.performRequest: Unexpected response code 400 for http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/GetBookingDetails
10-12 10:34:19.529 7149-7149/com.farehawker I/Error: com.android.volley.ServerError


The json I am sending is
{"EndUserIp":"216.10.251.69","TokenId":"0307b931-bd7d-4860-9c4d-4d65103ebddc","PNR":"ZERD8U","BookingId":"1401272"}

Postman request
Postman response

400 means that your server is down

You need to post the code snippet of API call and proper log from logcat.

@Sushil Kumar But it is working on postman.

show your code and also error logcat

@Jay I posted my Log and api call

@user1 Check if you have to add any required header in your code

show your postman screenshot also.

@Parul How can i check that?

@user1 Verify it with postman. As Tejas said, share your postman's screenshot

@Parul I have shared postman screen shot

@user1 Append "/" at the end of your url

@Parul I appended "/" at the end of url but it did not work

You changed your url from "http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/GetBookingDetails" to "http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/GetBookingDetails/"

@Parul String url="http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/GetBookingDetails/";

Replace your requestqueuw with below one:
RequestQueue requestQueue = Volley.newRequestQueue(this);
        try {
            String url = "http://api.tektravels.com/BookingEngineService_Air/AirService.svc/rest/GetBookingDetails/";
            url = url.replaceAll(" ", "%20");

            JSONObject jsonObject = new JSONObject();
            jsonObject.put("EndUserIp", "216.10.251.69");
            jsonObject.put("TokenId", "0307b931-bd7d-4860-9c4d-4d65103ebddc");
            jsonObject.put("PNR", "ZERD8U");
            jsonObject.put("BookingId", "1401272");
            Log.i("JsonObject", jsonObject.toString());
            JsonObjectRequest jsonobjectreq = new JsonObjectRequest(Request.Method.POST, url, jsonObject,
                    new Response.Listener<JSONObject>() {
                        @Override
                        public void onResponse(JSONObject response) {
                            Log.i("response", response.toString());
                            //progressDialog.dismiss();
                        }
                    },
                    // The final parameter overrides the method onErrorResponse() and passes VolleyError
                    //as a parameter
                    new Response.ErrorListener() {
                        @Override
                        // Handles errors that occur due to Volley
                        public void onErrorResponse(VolleyError error) {
                            Log.e("Volley", "Error");
                        }
                    }


            ) ;
 jsonobjectreq.setRetryPolicy(new DefaultRetryPolicy(
                    5000,
                    DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
                    DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
            jsonobjectreq.setShouldCache(false);
            requestQueue.add(jsonobjectreq);
            } catch (Exception e) {
            e.printStackTrace();
        }


In this code, I have only appended "/" at the end of url. I don't know , why it didn't work for you earlier.

why is it necessay to append / at the end of url?

Thanks for help.Can i have your email or whatsapp no

AFAIK you're sending JsonObjectRequest  to the server and for that, you need to pass Content-Type also with your Volley network call . 
In your Volley NetworkCall Attach this 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;
}


I think JsonObjectRequest  will automatically add "application/json" as header.

yes @Parul but I want to be sure that he's passing a proper request to the server . and we can't figure out problem until he posts some other detail also

Issue is volley do not support redirecting url. And the url is internally redirecting to new url with "/" at end. So @user1 Download Volley code from https://github.com/samkirton/android-volley and add it as module. I think redirect issue is solved in this code.
