Nsurl is actually what we see in the browser website address, this is not a string, why also write a nsurl it, mainly because the web address of the string is more complex, including a lot of request parameters, so in the request process need to parse out each department, so encapsulate a nsurl, The operation is very convenient:
[CPP]View Plaincopy
- 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]);
Results:
[CPP]View Plaincopy
- 2012-08-29 15:52:23.781 nsurl[3560:f803] Scheme:http
- 2012-08-29 15:52:32.793 nsurl[3560:f803] Host:www.baidu.com
- 2012-08-29 15:52:39.102 nsurl[3560:f803] Port: (NULL)
- 2012-08-29 15:52:42.590 nsurl[3560:f803] Path:/s
- 2012-08-29 15:52:52.516 nsurl[3560:f803] Relative path:/s
- 2012-08-29 15:53:05.576 nsurl[3560:f803] Path components as array: (
- "/",
- S
- )
- 2012-08-29 15:53:32.861 nsurl[3560:f803] Parameter string: (NULL)
- 2012-08-29 15:53:37.528 nsurl[3560:f803] Query:tn=baiduhome_pg&bs=nsrul&f=8&rsv_bp=1&rsv_spt=1 &wd=nsurl&inputt=2709
- 2012-08-29 15:53:52.942 nsurl[3560:f803] Fragment: (NULL)
- 2012-08-29 15:53:54.539 nsurl[3560:f803] User: (NULL)
- 2012-08-29 15:53:57.808 nsurl[3560:f803] Password: (NULL)
IOS Nsurl Basic Operations