我在服务器上遇到了一个API,但是我收到了此错误消息:
BasicNetwork.performRequest:意外的响应代码500和onErrorResponse:错误:null
我尝试了所有操作,但根本没有工作。请帮忙。
这是创建JSON数组的代码,因为我需要一个参数作为JSON数组。
private void createJSONOrder() {
String firstDay = etDate1.getText().toString() + "##" + etStartTime1.getText().toString() + "##" + etEndTime1.getText().toString();
String secondDay = etDate2.getText().toString() + "##" + etStartTime2.getText().toString() + "##" + etEndTime2.getText().toString();
selectionItems.add(firstDay);
selectionItems.add(secondDay);
String[] blist = new String[selectionItems.s¬ize()];
Log.e("tag", "array" + blist.length + selectionItems);
for (int i = 0; i < selectionItems.size(); i++) {
blist[i] = selectionItems.get(i);
}
Log.e("tag", "arrayList" + blist[0]);
weekdata = new JSONArray();
for (int i = 0; i < blist.length; i++) {
weekdata.put(blist[i]); // create array and add items into that
}
Log.e("TAG", "jsonProduct: " + weekdata);
generataeInvoiceApi();
}
API调用代码:
private void generataeInvoiceApi() {
String tag_json_obj = "json_obj_req";
String url = Constants.GENERATE_INVOICE;
pBar.setVisibility(View.VISIBLE);
final SessionManager session = new SessionManager(getActivity());
final HashMap<String, String> loggedDetail = session.getLoggedDetail();
HashMap<String, String> params = new HashMap<String, String>();
params.put("package_id", package_id);
params.put("week", weekName);
params.put("weekdata", weekdata.toString());
Log.e("Tag", "generateInvoiceParam:" + params);
JsonObjectRequest jsonObjReq = new JsonObjectRequest(Request.Method.POST,
url, new JSONObject(params),
new Response.Listener<JSONObject>() {
@Override
public void onResponse(JSONObject response) {
Log.e("generate_response", response.toString());
pBar.setVisibility(View.GONE);
}
}, new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
VolleyLog.e("Error: " + error.getMessage());
// handle error
pBar.setVisibility(View.GONE);
}
}) {
@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");
headers.put("Authorization", "Bearer " + loggedDetail.get("api_token"));
return headers;
}
};
jsonObjReq.setRetryPolicy(new DefaultRetryPolicy(
100000,
DefaultRetryPolicy.DEFAULT_MAX_RETRIES,
DefaultRetryPolicy.DEFAULT_BACKOFF_MULT));
AppController.getInstance().addToRequestQueue(jsonObjReq, tag_json_obj);
}
}
我要发送的参数的格式为:
{weekdata=["2019-04-01##2:15##2:15","2019-04-03##2:15##2:15"], package_id=44, week=Apr 01, 2019}
一切都很好。网址正在iOS端上运行,但无法在我的应用中使用。我该怎么解决?
答案 0 :(得分:0)
尝试更改
HashMap<String, String> params = new HashMap<String, String>();
通过
JSONObject params = new JSONObject();