今天在做项目的时候突然遇到了NSURLComponents,发现以前没有用到过,就想简单的查一下,后来就发现了更多的东西,这是我看资料和一些自己简单的理解.
维基百科:URI可以分为URL,URN或同时具备locators 和names特性的一个东西。URN作用就好像一个人的名字,URL就像一个人的地址。换句话说:URN确定了东西的身份,URL提供了找到它的方式。
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/s?tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709"];
NSLog(@"Scheme: %@", [url scheme]);
NSLog(@"Host: %@", [url host]);
NSLog(@"Port: %@", [url port]);
NSLog(@"Path: %@", [url path]);
NSLog(@"Relative path: %@", [url relativePath]);
NSLog(@"Path components as array: %@", [url pathComponents]);
NSLog(@"Parameter string: %@", [url parameterString]);
NSLog(@"Query: %@", [url query]);
NSLog(@"Fragment: %@", [url fragment]);
NSLog(@"User: %@", [url user]);
NSLog(@"Password: %@", [url password]);
分隔
2015-12-10 21:53:57.171 [4697:358837] Scheme: http
2015-12-10 21:53:57.171 [4697:358837] Host: www.baidu.com
2015-12-10 21:53:57.172 [4697:358837] Port: (null)
2015-12-10 21:53:57.172 [4697:358837] Path: /s
2015-12-10 21:53:57.172 [4697:358837] Relative path: /s
2015-12-10 21:53:57.172 [4697:358837] Path components as array: (
"/",
s
)
2015-12-10 21:53:57.172 [4697:358837] Parameter string: (null)
2015-12-10 21:53:57.173 [4697:358837] Query: tn=baiduhome_pg&bs=NSRUL&f=8&rsv_bp=1&rsv_spt=1&wd=NSurl&inputT=2709
2015-12-10 21:53:57.173 [4697:358837] Fragment: (null)
2015-12-10 21:53:57.173 [4697:358837] User: (null)
2015-12-10 21:53:57.173 [4697:358837] Password: (null)