每当我尝试在我的app中使用api时获得此响应。这是我在api hit中获得的响应。我在头文件中放置的内容类型是.application / json; charset = utf-8但在respnose中它们是错误并显示ascii字符。需要帮助解决它。
> <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML
> 4.01//EN""http://www.w3.org/TR/html4/strict.dtd"> <HTML><HEAD><TITLE>Bad Request</TITLE> <META HTTP-EQUIV="Content-Type"
> Content="text/html; charset=us-ascii"></HEAD> <BODY><h2>Bad Request -
> Invalid Header</h2> <hr><p>HTTP Error 400. The request has an invalid
> header name.</p> </BODY></HTML>
这是我放置标题的类..
public class CustomJSONStringRequest extends StringRequest { public CustomJSONStringRequest(int method, String url, Response.Listener<String> listener, Response.ErrorListener errorListener) { super(method, url, listener, errorListener); } @Override public Map<String, String> getHeaders() throws AuthFailureError { HashMap<String, String> headers = new HashMap<String, String>(); headers.put("Cache-Control","no-cache"); headers.put("Content-Type", "application/json; charset=utf-8"); headers.put("Authorization", "....."); headers.put("X-API-KEY", "......"); return headers; } }
答案 0 :(得分:2)
尝试使用“接受”而不是“内容类型”
答案 1 :(得分:0)
您需要在调用时正确提供标题名称