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

安卓 AsyncHttpClient - “Content-Type not allowed!”的更多相关文章

  1. Jsoup问题---获取http协议请求失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    Jsoup问题---获取http协议请求失败 1.问题:用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不 ...

  2. DOM解析XML报错:Content is not allowed in prolog

    报错内容为: Content is not allowed in prolog. Nested exception: Content is not allowed in prolog. 网上所述总结来 ...

  3. Jsoup获取部分页面数据失败 org.jsoup.UnsupportedMimeTypeException: Unhandled content type. Must be text/*, application/xml, or application/xhtml+xml.

    用Jsoup在获取一些网站的数据时,起初获取很顺利,但是在访问某浪的数据是Jsoup报错,应该是请求头里面的请求类型(ContextType)不符合要求. 请求代码如下: private static ...

  4. SharePoint自动化系列——Add content type to list.

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 将创建好的content type(若是跨web application需要事先publish c ...

  5. SharePoint自动化系列——Content Type相关timer jobs一键执行

    转载请注明出自天外归云的博客园:http://www.cnblogs.com/LanTianYou/ 背景: 在SharePoint Central Administration->Monito ...

  6. 转载 SharePoint【Site Definition 系列】– 创建Content Type

    转载原地址:  http://www.cnblogs.com/wsdj-ITtech/archive/2012/09/01/2470274.html Sharepoint本身就是一个丰富的大容器,里面 ...

  7. the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header

    the request doesn't contain a multipart/form-data or multipart/form-data stream, content type header ...

  8. 转:通过ant来批量执行jmeter脚本,并生成报告(附: 生成报告时报“Content is not allowed in prolog”这个错误的解决方案)

    最近在使用jmeter写脚本来进行测试,最终写了很多份脚本,然后,就在想,这么多脚本,我不可能一个一个的手动去点啊,有没有什么办法来批量运行Jmeter脚本呢? 这个时候,自然而然地想到了万能的ant ...

  9. Springs Element 'beans' cannot have character [children], because the type's content type is element-only

    Springs Element 'beans' cannot have character [children], because the type's content type is element ...

  10. Caused by: org.xml.sax.SAXParseException; lineNumber: 1; columnNumber: 1; Content is not allowed in

    1.错误描述 严重: Exception sending context initialized event to listener instance of class org.springframe ...

随机推荐

  1. 35个让人惊讶的CSS3动画效果

    1. Pure CSS Coke Can 2. Colorful Clock 3. jQuery DJ Hero 4. Animated Pricing Column 5. Slick jQuery  ...

  2. 阿里云构建Kafka单机集群环境

    简介 在一台ECS阿里云服务器上构建Kafa单个集群环境需要如下的几个步骤: 服务器环境 JDK的安装 ZooKeeper的安装 Kafka的安装 1. 服务器环境 CPU: 1核 内存: 2048 ...

  3. LCX端口内网映射转发

    这几天在渗透一家奶茶店的时候, 使用溢出攻击获得了奶茶店shell, 截屏以后发现该电脑有安装sqlserver, 但是数据库无法远程连接, 所以我决定使用端口映射工具突破端口连接限制: 我的机器地址 ...

  4. 10分钟精通require.js

    require.js的诞生,就是为了解决这两个问题:(1)实现js文件的异步加载,避免网页失去响应:(2)管理模块之间的依赖性,便于代码的编写和维护. 实例下载:require.js应用实例 一.re ...

  5. windows 2012授权模型

    转自:http://www.aidanfinn.com/?p=13090 Remember that Microsoft licenses its servers at the physical le ...

  6. JAVA中JDBC连接Mysql数据库简单测试

    一.引用库 maven库:mysql:mysql-connector-java:6.0.6 二.SDK环境 JAVA JDK10 三.测试代码 package com.mysql.mysqlconne ...

  7. 浅谈mysql中utf8和utf8mb4区别

    转自:http://ourmysql.com/archives/1402  实践过程中发现有时mysql的字符集会引起故障,所以需要了解下这个知识点. 一.简介 MySQL在5.5.3之后增加了这个u ...

  8. powx-n 分治实现乘方

    题目描述 Implement pow(x, n). AC: class Solution { public: double pow(double x, int n) { && n == ...

  9. java 获取class文件所在路径

      java 获取class文件所在路径 CreateTime--2017年11月14日15:14:32 Author:Marydon 1.获取class文件所在路径(磁盘路径.绝对路径) // 获取 ...

  10. 〖Android〗简单隐藏Android虚拟键盘的方法

    在Android使用 input 输入文本时,不期望出现虚拟键盘: 一般情况下,大家会把键盘给卸载,不过也有简单的方法: 就是下载一个 com.wparam.nullkeyboard (NullKey ...