NSURL 检查是否是网页或可下载文件

发布于 2025-01-06 06:19:35 字数 300 浏览 4 评论 0原文

我下载随机 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

最单纯的乌龟 2025-01-13 06:19:35

NSURLResponse 中,您可以检查 MIMEType 来检查文件类型,并检查 expectedContentLength 来检查长度以及开始实际下载之前的所有内容。

From NSURLResponse you can check MIMEType to check the file type and expectedContentLength to check the length and all that before starting to actually download it.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文