我正在尝试在Volley中编写POST调用,以将
XML正文发送到服务器.我无法正确设置Content-Type标头.
基本的StringRequest如下所示:
StringRequest folderRequest = new StringRequest(Method.POST,submitInterviewUrl,myListener,myErrorListener) { @Override public byte[] getBody() throws AuthFailureError { String body = "some text"; try { return body.getBytes(getParamsEncoding()); } catch (UnsupportedEncodingException uee) { throw new RuntimeException("Encoding not supported: " + getParamsEncoding(),uee); } } @Override public Map<String,String> getHeaders() throws AuthFailureError { Map<String,String> headers = new HashMap<String,String>(); headers.put("Content-Type","application/xml"); return headers; } };
我重写getHeaders()以提供我想要的Content-Type标头 – application / xml.
这是基于与此类似的建议问题:
> Android Volley Post Request Header not changing
发送请求后,Volley会自动添加第二个Content-Type标头,因此标题如下所示:
Content-Type: application/xml Content-Type: application/x-www-form-urlencoded; charset=UTF-8
我已尝试跟踪基本请求代码,但无法找到此额外标头的来源.