AFNetworking set image without extension

丶灬走出姿态 提交于 2020-01-05 23:42:12

问题


There is a method in AFNetworking that can set image conveniently:

 - (void)setImageWithURL:(NSURL *)url 
   placeholderImage:(UIImage *)placeholderImage

but if the url image have no extension(like http://static.qyer.com/album/user/330/21/QkpVQBsHaA/670), there are some problems,sometimes the image can be displayed exactly some times it is not displayed.

I found a method

  [AFImageRequestOperation addAcceptableContentTypes:<#(NSSet *)contentTypes#>];

how should I set the contentTypes?


回答1:


If you curl the URL provided, you can see the problem:

curl -i -X HEAD http://static.qyer.com/album/user/330/21/QkpVQBsHaA/670

HTTP/1.0 200 OK
Server: nginx/1.0.11
Date: Fri, 29 Mar 2013 02:03:24 GMT
Content-Type: application/octer-stream
Last-Modified: Tue, 19 Mar 2013 09:40:23 GMT
ETag: "53430075-9814c-4d843e4fc6fc0"
Accept-Ranges: bytes
Content-Length: 622924
Powered-By-ChinaCache: MISS from 060531Q354
Powered-By-ChinaCache: MISS from 060532235y
Connection: close

Content-Type: application/octer-stream (which is, strangely, a misspelling of application/octet-stream), is not a valid image mime type. If you have any control over the server, I would strongly recommend you fix this to send real mime types—for the sake of everyone accessing the CDN.

Otherwise, I would recommend you add */* to the list of acceptable content types. This should accept anything thrown at it. You can also manually specify any content types you might expect the CDN to serve, including application/octer-stream.



来源:https://stackoverflow.com/questions/15696166/afnetworking-set-image-without-extension

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!