
基本的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/xmlContent-Type: application/x-www-form-urlencoded; charset=UTF-8
如何设置正确的标题?或删除不正确的标题?
我已尝试跟踪基本请求代码,但无法找到此额外标头的来源.
解决方法 Volley不会将Content-Type标头与其他标头的处理方式相同.特别是,重写getheaders()以更改内容类型并不总是有效.执行此 *** 作的正确方法是覆盖getbodyContentType():
public String getbodyContentType() { return "application/xml"; } 我通过查看JsonRequest类的代码找到了这个.
Delyan在回答这个相关问题时也提到了这个问题:
> how to execute PUT request in Android Volley?
总结以上是内存溢出为你收集整理的android – Volley Content-Type标头不更新全部内容,希望文章能够帮你解决android – Volley Content-Type标头不更新所遇到的程序开发问题。
如果觉得内存溢出网站内容还不错,欢迎将内存溢出网站推荐给程序员好友。
欢迎分享,转载请注明来源:内存溢出
微信扫一扫
支付宝扫一扫
评论列表(0条)