ObjectC,NSURL,统一资源定位器 -电脑资料

电脑资料 时间:2019-01-01 我要投稿
【meiwen.anslib.com - 电脑资料】

    今天晚上最后一个例子,写完休息娱乐一会,

ObjectC,NSURL,统一资源定位器

    URL,统一资源定位器,可以定位网络上的一个资源。

    没啥难的,还是对象、方法、API。和Java等语言没有啥区别。

    不亲自一点点写一遍,印象不深,今后进一步深入学习iOS时,会遇到很多问题,倒是再回头看,也没效率。

    代码

////  main.m//  NSURLTest////  Created by fansunion on 15/12/2.//  Copyright (c) 2015年 demo. All rights reserved.//#import<foundation foundation.h="">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);        //使用URL对应的资源来初始化NSString对象        NSString* content =[NSString stringWithContentsOfURL: url encoding:NSUTF8StringEncoding error:nil];        NSLog(@"%@",content);    }    return 0;}</foundation>

    程序输出

    2015-12-02 21:07:54.545 NSURLTest[5619:393442] scheme : http

    2015-12-02 21:07:54.546 NSURLTest[5619:393442] host : blog.csdn.net

    2015-12-02 21:07:54.546 NSURLTest[5619:393442] port : (null)

    2015-12-02 21:07:54.546 NSURLTest[5619:393442] path : /FansUnion

    2015-12-02 21:08:08.555 NSURLTest[5619:393442]

    更多html内容,没有展示出来,太长了,

电脑资料

ObjectC,NSURL,统一资源定位器》(http://meiwen.anslib.com)。

    比较奇怪的是,端口号port为啥是null,难道不是80么?

最新文章