您的位置:首页 > 理论基础 > 计算机网络

安卓 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());
}
}
});
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: