使用 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());}}});    

本文转自 netcorner 博客园博客,原文链接: http://www.cnblogs.com/netcorner/p/4851041.html  ,如需转载请自行联系原作者

安卓 AsyncHttpClient - “Content-Type not allowed!”相关推荐

  1. SharePoint2010 内容类型剖析(Content Type/ 內容類型)

    原文地址:http://sharepoint410.wordpress.com/2011/01/06/sharepoint2010-%E5%86%85%E5%AE%B9%E7%B1%BB%E5%9E% ...

  2. restTemplate http请求报错:no suitable HttpMessageConverter found for response type and content type

    报错信息: org.springframework.web.client.UnknownContentTypeException: Could not extract response: no sui ...

  3. Posted content type isn't multipart/form-data

    版权声明:欢迎转载,请注明沉默王二原创. https://blog.csdn.net/qing_gee/article/details/48712507 在有文件上传的表单提交过程中,搞不好就会报Po ...

  4. Maven报错解决:Element 'dependency' cannot have character [children], because the type's content type is

    在用maven的时候遇到报错: Element 'dependency' cannot have character [children], because the type's content ty ...

  5. 用VS向SharePoint中部署添加List 并指定应用的Content Type

    在SharePoint Project中添加相应的Item,完全用界面的形式向EricSunArticlesList中添加好对应的Column,之后用Feature将List添加到SharePoint ...

  6. Spring Boot——[Content type 'application/x-www-form-urlencoded;charset=UTF-8' not supported]解决方案

    问题描述 2020-02-13 19:32:04.322 WARN 109508 --- [p-nio-80-exec-4] .m.m.a.ExceptionHandlerExceptionResol ...

  7. : Content type 'text/plain;charset=UTF-8' not supported

    : Content type 'text/plain;charset=UTF-8' not supported

  8. eclipse 设置 content type 编码格式

    前言 Eclipse Version: 2019-12 (4.14.0) 操作 打开Preferences.菜单路径为:Window–> Preferences 在搜索框中输入:content ...

  9. tom启动报错:org.xml.sax.SAXParseException: Content is not allowed in prolog.

    警告: Catalina.start using conf/server.xml: org.xml.sax.SAXParseException: Content is not allowed in p ...

  10. org.xml.sax.SAXParseException: Content is not allowed in trailing section

    2019独角兽企业重金招聘Python工程师标准>>> org.xml.sax.SAXParseException: Content is not allowed in traili ...

最新文章

  1. Roger Ver:BCH比BCE更适合机构投资者
  2. 写入时复制(Copy-on-write)机制
  3. LCD液晶屏静电防护方案
  4. spark太基础了,今天聊下阿里 2 面必问的数据中台
  5. .Net Core with 微服务 - Seq 日志聚合
  6. ZZULIOJ 1073:级数求和
  7. nginx下目录浏览及其验证功能、版本隐藏等配置记录
  8. python写gui、主体程序必须放进函数里吗_Python学习(二):使用TKinter进行GUI程序设计...
  9. 【优化电价】基于matlab内点法求解实时电价最优问题【含Matlab源码 1161期】
  10. 安装IBM Data Studio Client
  11. apache+php+mysql 常见集成环境安装包
  12. printf输出格式化
  13. linux终端清除命令,ubuntu清除命令行记录
  14. idea双击打不开的解决方案
  15. tcgames使用有延迟_Tcgames下载使用方法
  16. Android 性能优化四个方面总结
  17. Struts2中XXX.Action类中方法的访问(三种方式)
  18. 数字化医院中智慧医疗的具体应用
  19. 带你认识不一样的常春藤之一的普林斯顿大学
  20. 【Matlab】如何绘制errorbar误差棒

热门文章

  1. centos7 安装php nts,centos7安装php7,亲测可行
  2. 直流电路相关计算机,计算机专业用复杂直流电路习题(各种方法运用).doc
  3. mysql 按小时分组统计_PowerBI业务分析:按排名分组统计
  4. linux内核报告,Linux升级内核报告.docx
  5. matlab-等高线图-三维曲线的绘制
  6. matlab 罗盘图与羽毛图
  7. FPGA之道(18)FPGA设计的编译过程
  8. 《压缩感知理论及其研究进展》读书笔记
  9. 《代码整洁之道》(Clean Code)- 读书笔记
  10. QApplication类详细描述