IOS Nsurl Basic Operations

Source: Internet
Author: User

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
  1. 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 "];
  2. NSLog (@"scheme:%@", [url scheme]);
  3. NSLog (@"host:%@", [url host]);
  4. NSLog (@"Port:%@", [url port]);
  5. NSLog (@"path:%@", [url path]);
  6. NSLog (@"Relative path:%@", [url relativepath]);
  7. NSLog (@"Path components as array:%@", [url pathcomponents]);
  8. NSLog (@"Parameter string:%@", [url parameterstring]);
  9. NSLog (@"query:%@", [url query]);
  10. NSLog (@"Fragment:%@", [url Fragment]);
  11. NSLog (@"User:%@", [url user]);
  12. NSLog (@"Password:%@", [url Password]);

Results:

[CPP]View Plaincopy
    1. 2012-08-29 15:52:23.781 nsurl[3560:f803] Scheme:http
    2. 2012-08-29 15:52:32.793 nsurl[3560:f803] Host:www.baidu.com
    3. 2012-08-29 15:52:39.102 nsurl[3560:f803] Port: (NULL)
    4. 2012-08-29 15:52:42.590 nsurl[3560:f803] Path:/s
    5. 2012-08-29 15:52:52.516 nsurl[3560:f803] Relative path:/s
    6. 2012-08-29 15:53:05.576 nsurl[3560:f803] Path components as array: (
    7. "/",  
    8. S
    9. )
    10. 2012-08-29 15:53:32.861 nsurl[3560:f803] Parameter string: (NULL)
    11. 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
    12. 2012-08-29 15:53:52.942 nsurl[3560:f803] Fragment: (NULL)
    13. 2012-08-29 15:53:54.539 nsurl[3560:f803] User: (NULL)
    14. 2012-08-29 15:53:57.808 nsurl[3560:f803] Password: (NULL)

IOS Nsurl Basic Operations

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.