Object-C, NSURL, unified Resource Locator

Source: Internet
Author: User

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?

 

 

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.