Which schemes does NSURL / NSURLRequest / NSURLConnection understand?
Apple says, NSURL is developed using RFC 1738 (and some othe开发者_Go百科rs).
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.
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 suitable NSURLProtocol
subclass registered for that. But out of the box, it is documented to support http:
, https:
, ftp:
and file:
. 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.
The built-in URL protocols can handle the schemes http
, https
, file
, ftp
, about
, and data
.
You can define your own protocols to make the NSURL system automatically handle new schemes using the NSURLProtocol
class.
精彩评论