Object-C, NSURL, unified Resource Locator
The last example of this evening is to finish the rest and play for a while.
URL, unified resource locator, can locate a resource on the network.
There is no difficulty, but objects, methods, and APIs. It is no different from other languages such as Java.
I don't personally write it once, but I'm not very impressed. I will encounter many problems when I further study iOS in the future, but it is inefficient to look back.
Code
/// Main. m // NSURLTest /// Created by fansunion on 15/12/2. // Copyright (c) 2015 demo. All rights reserved. // # import
Int main (int argc, const char * argv []) {@ autoreleasepool {NSString * str = @ "http://blog.csdn.net/FansUnion"; NSURL * url = [NSURL URLWithString: str]; NSString * scheme = [url scheme]; NSString * host = [url host]; NSString * port = [url port]; NSString * path = [url path]; NSLog (@ "scheme: % @", scheme); NSLog (@ "host: % @", host); NSLog (@ "port: % @", port ); NSLog (@ "path: % @", path); // use the resource corresponding to the URL to initialize the NSString object NSString * content = [NSString stringWithContentsOfURL: url encoding: NSUTF8StringEncoding error: nil]; NSLog (@ "% @", content);} return 0 ;}
Program output
21:07:54. 545 NSURLTest [5619: 393442] scheme: http
21:07:54. 546 NSURLTest [5619: 393442] host: blog.csdn.net
21:07:54. 546 NSURLTest [5619: 393442] port: (null)
21:07:54. 546 NSURLTest [5619: 393442] path:/FansUnion
21:08:08. 555 NSURLTest [5619: 393442]
More html content is not displayed. It is too long.
It is strange that the port number is null, isn't it 80?