NSURL / NSURLRequest / NSURLConnection 理解哪些方案?
Apple 表示,NSURL 是使用 RFC 1738(以及其他一些)开发的。
现在 RFC 1738 仅指定 Web URL 具有方案和方案特定部分。
我想知道 NSURL 理解的所有方案。因为我将它与 NSURLRequest 和 NSURLConnection (所谓的“URL加载器系统”)一起使用,所以我必须知道它们理解的所有方案。
为什么?因为我只是想知道。 Apple 没有在文档中详细说明这一点,只是说遵守 RFC 1738。这说明了很多,但也没有说明什么。
Apple says, NSURL is developed using RFC 1738 (and some others).
Now RFC 1738 specifies only that an web URL has a scheme and a scheme specific part.
I want to know all the schemes which NSURL understands. And because I use it with NSURLRequest and NSURLConnection (the so called "URL Loader System"), I must know all the schemes which these understand.
Why? Because I just want to know. Apple does not go into detail about it in the documentation, the just say the comply to RFC 1738. That tells a lot and also nothing.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
NSURL
“支持”任何方案,因为它不知道如何使用相关方案。它只是 URL 概念的包装。同样,
NSURLRequest
不知道更多,但它确实有能力存储可能特定于协议的额外信息。NSURLConnection
是您开始获取更多特定于协议的地方。NSURLConnection
能够支持您向其抛出的任何 URL,前提是为此注册了合适的NSURLProtocol
子类。但开箱即用,记录支持http:
、https:
、ftp:
和文件:。您可以通过快速的
+canHandleRequest:
调用来测试它。根据经验,系统也支持
data:
URL。我已向 Apple 提交了radar://problem/13649313,要求他们记录这一点。NSURL
"supports" any scheme, because it knows nothing about how to use the scheme in question. It is just a wrapper around the concept of a URL.Likewise,
NSURLRequest
knows no more, but it does have capability to store extra information which could be protocol-specific.NSURLConnection
is where you start getting more protocol-specific.NSURLConnection
is capable of supporting any URL you throw at it, provided there is a suitableNSURLProtocol
subclass registered for that. But out of the box, it is documented to supporthttp:
,https:
,ftp:
andfile:
. You can test it with a quick+canHandleRequest:
call.Empirically, the system supports
data:
URLs too. I have filed radar://problem/13649313 with Apple asking them to document this.内置的 URL 协议可以处理
http
、https
、file
、ftp
、about 等方案
和数据
。您可以使用
NSURLProtocol
类定义自己的协议,使 NSURL 系统自动处理新方案。The built-in URL protocols can handle the schemes
http
,https
,file
,ftp
,about
, anddata
.You can define your own protocols to make the NSURL system automatically handle new schemes using the
NSURLProtocol
class.