我在我的应用程序中尝试获取响应,在使用volley库调用API时,它会给出com.android.volley.ServerError
和响应代码400。
以下是我的代码:
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();
}
}
它在Postman中能正常工作。我遇到的错误是:
com.android.volley.ServerError
日志是
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
我发送的json数据是:
{"EndUserIp":"216.10.251.69","TokenId":"0307b931-bd7d-4860-9c4d-4d65103ebddc","PNR":"ZERD8U","BookingId":"1401272"}