使用android-async-http下载图片时出现org.apache.http.client.HttpResponseException: Content-Type not allowed的错误
来源:互联网 发布:c语言数据类型怎么用 编辑:程序博客网 时间:2024/05/21 14:54
昨晚使用android-async-http库进行图片下载的时候提示了如上错误,Content-Type不被允许。此时我们可以打印出来http请求的一些信息,看一下所需要的Content-Type的类型。如下,在onFailure方法里面打印日志:
HttpUtils.getInstance().getImgFromUrl(Constant.BeforeSendMsgVerfityImg, new BinaryHttpResponseHandler(allowedContentTypes) {@Overridepublic void onSuccess(int arg0, Header[] arg1, byte[] arg2) {Bitmap bmp = BitmapFactory.decodeByteArray(arg2, 0, arg2.length);ivCodeImg.setImageBitmap(bmp);}@Overridepublic void onFailure(int arg0, Header[] arg1, byte[] arg2, Throwable arg3) {// TODO Auto-generated method stubLog.e("yy:", "onFailure: " + arg3); for (Header header : arg1){ Log.i("yy", header.getName()+" / "+header.getValue()); //这里是打印的http信息 }}});
日志如下;
红框内即是我们所需要添加的类型,请求图片时作如下处理:
String[] allowedContentTypes = new String[] { "image/jpeg;charset=UTF-8" }; //我这里只限定了一种图片格式即可正确下载图片。
0 0
- 使用android-async-http下载图片时出现org.apache.http.client.HttpResponseException: Content-Type not allowed的错误
- 使用AsyncHttpClient下载图片出现org.apache.http.client.HttpResponseException: Content-Type not allowed!
- carrot2 Workbench org.apache.http.client.HttpResponseException: Not Found 以及其他类找不到错误的解决办法
- Android AsyncHttpClient 下载文件 Content-Type not allowed! 错误
- 解决Android Studio在使用android-async-http出现import org.apache.http.Header不可用
- Android 网络请求框架android-async-http的一个细节问题(org.apache.http.client.CircularRedirectException异常)
- AndroidStudio导入xUtils时出现 找不到org.apache.http.client.method等错误
- 11. 使用Android-async-http第三方库时import org.apache.http 导入无效
- Android 使用android-async-http网络请求框架出现Header[]不识别错误的解决办法
- 【已解决】使用android-async-http网络请求框架出现Header[]不识别错误的解决办法
- android "Could not find class 'org.apache.http.entity.mime.content.FileBody" error
- org.apache.http.client.HttpClient
- org.apache.http.client.HttpClient
- org.apache.http.client.CircularRedirectException
- java利用org.apache.http.client下载文件
- org.apache.http.client.HttpClient 访问服务器限速下载文件
- Android解决"关于Xutils框架出现无法访问HttpRequestBase 找不到org.apache.http.client.methods.HttpRequestBase解决方案
- android-async-http异步出现的问题
- IIS tomcat共用80端口解决一个IP多个域名:使用Nginx反向代理方式使两者兼容
- Android WebView 远程代码执行漏洞
- VC 用发音函数Beep()播放简谱音乐
- 开源控件ExpandableTextView的使用
- 【LeetCode】13Roman to Integer
- 使用android-async-http下载图片时出现org.apache.http.client.HttpResponseException: Content-Type not allowed的错误
- android 按原始数据读出资源
- iOS CoreImage专题(二) —— 进阶
- 简单的使用GitHub,代码管理
- MIT算法导论-第六讲-顺序统计问题
- initWithNibName、initWithCoder、awakeFromNib、initWithNibName、loadNibNamed
- 表单中Readonly和Disabled的区别
- 显示通知小红点
- 图像卷积的理解