[英]Volley - BasicNetwork.performRequest: Unexpected response code 400 POST
Postman Header 邮差标题
[{"key":"Content-Type","name":"Content-Type","type":"text","value":"application/json"},{"key":"token","type":"text","value":"ffBJpLW55i"}]
even if i put token value instead of the token string it wont work 即使我放置令牌值而不是令牌字符串也无法正常工作
headers.put("Content-Type", "application/json");
headers.put("token", "ffBJpLW55i");
2019-03-15 21:51:15.384 20577-20620/com.sleepyhitman.ab4_internship_2019try2 E/Volley: [816] BasicNetwork.performRequest: Unexpected response code 400 for https://tralalala.com/api-spot-get-all 2019-03-15 21:51:15.384 20577-20620 / com.sleepyhitman.ab4_internship_2019try2 E / Volley:[816] BasicNetwork.performRequest: https ://tralalala.com/api-spot-get-all的意外响应代码400
private void loadRecyclerViewData(final String token){
RequestQueue requestQueue = Volley.newRequestQueue(this);
StringRequest listRequest = new StringRequest(Request.Method.POST,URL_DATA+"api-spot-get-all",
new Response.Listener<String>() {
@Override
public void onResponse(String response) {
try {
JSONObject jsonObject = new JSONObject(response);
JSONArray array = jsonObject.getJSONArray("result");
for (int i =0; i<array.length(); i++) {
JSONObject o = array.getJSONObject(i);
ListItem list = new ListItem(
o.getString("id"),
o.getString("name"),
o.getString("country"),
o.getString("whenToGo"),
o.getBoolean("isFavorite")
);
listItems.add(list);
}
ListItemAdapter listItemAdapter = new ListItemAdapter(getApplicationContext(), listItems);
recyclerView.setAdapter(listItemAdapter);
} catch (JSONException e) {
e.printStackTrace();
}
//
}
},
new Response.ErrorListener() {
@Override
public void onErrorResponse(VolleyError error) {
}
}){
@Override
public Map<String, String> getHeaders() throws AuthFailureError {
HashMap<String, String> headers = new HashMap<String, String>();
headers.put("Content-Type", "application/json");
headers.put("token", token);
return headers;
}
protected Map<String, String> getParams() {
Map<String, String> params = new HashMap<String, String>();
params.put("country", "");
params.put("windProbability", "");
return params;
}
};
requestQueue.add(listRequest);
}
This part is the error part of your volley request, 这部分是你的截击请求的错误部分,
URL_DATA+"api-spot-get-all"
There should be a URL in string format as you are using StringRequest. 在使用StringRequest时,应该有一个字符串格式的URL。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.