NSURL 检查是否是网页或可下载文件
我下载随机 URL。有没有办法查明 URL 是指网站还是可下载文件?
我目前使用这个:
[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:strURL] encoding:NSASCIIStringEncoding error:&error];
设置 URL 后面的网站/文件的文件大小限制也是一个选项。
有人对如何查找网站或可下载文件和/或可下载文件的大小之间的差异有任何建议吗?
谢谢!
I download random URL's. Is there a way to find out if the URL is referring to a website or a downloadable file?
I currently use this:
[[NSString alloc] initWithContentsOfURL:[NSURL URLWithString:strURL] encoding:NSASCIIStringEncoding error:&error];
Setting a limit to the filesize of the website/file behind the URL is also an option.
Does anyone has any suggestions about how to find the difference between website or downloadable file and/or the size of the downloadable file?
Thnx!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
从
NSURLResponse
中,您可以检查MIMEType
来检查文件类型,并检查expectedContentLength
来检查长度以及开始实际下载之前的所有内容。From
NSURLResponse
you can checkMIMEType
to check the file type andexpectedContentLength
to check the length and all that before starting to actually download it.