【发布时间】:2018-10-12 04:50:29
【问题描述】:
我尝试在我的应用程序中获得响应,当我尝试使用 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();
}
}
它在邮递员中工作。我得到的错误
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"}
【问题讨论】:
-
400 表示您的服务器已关闭
-
您需要发布API调用的代码sn-p和来自logcat的正确日志。
-
@Sushil Kumar 但它正在使用邮递员。
-
显示你的代码和错误日志
-
@Jay 我发布了我的日志和 api 调用