安卓 AsyncHttpClient - “Content-Type not allowed!”
2015-10-01 15:16
429 查看
使用 http://loopj.com/android-async-http/ 的异步网络请求工具使用BinaryHttpResponseHandler来完成文件下载时总是报错,“org.apache.http.client.HttpResponseException: Content-Type not allowed!”。若缺少某个请求的类型,比如我下载一个jpg文件,只要加上“image/jpg;charset=UTF-8” ,若对于html文件后来加上“text/html;charset=UTF-8” 就解决问题了。完整代码如下:
String[] allowedContentTypes = new String[] { "text/html;charset=UTF-8", "image/jpg;charset=UTF-8"}; String urlStr="your request url"; HttpUtil.get(urlStr, new BinaryHttpResponseHandler(allowedContentTypes) { public void onSuccess(int i, org.apache.http.Header[] headers, byte[] bytes) { Log.d("myingwill","ok"); } public void onFailure(int i, org.apache.http.Header[] headers, byte[] bytes, java.lang.Throwable throwable) { Log.d("myingwill",throwable.toString()); for (org.apache.http.Header header : headers) { Log.i("myingwill", header.getName()+" / "+header.getValue()); } } });
相关文章推荐
- ECharts+BaiduMap+HT for Web网络拓扑图应用
- 秒针系统网络广告交易平台介绍
- 秒针系统网络广告交易平台介绍
- 秒针系统网络广告交易平台介绍
- [网络和多线程]7、主队列
- 网络通信 --> TCP三次握手和四次挥手
- Apache HTTP Server2.4安装
- NetWorkTool工具类之网络请求
- 构建高性能WEB之HTTP首部优化
- httpget
- TCP/IP协议原理与应用笔记11:TCP/IP中地址与层次关系
- TCP浅谈(上)
- TCP/IP相关知识点
- 理解HTTP/304响应
- 妈咪212网络搜索功能,打开它
- c# HttpWebRequest 代码手动设置cookies的简单办法
- HTTP协议简述
- 构架https服务器
- http header 详解
- zeromq源码分析–TCP连接处理流程