ObjectC,NSURL,統一資源定位器 -電腦資料

電腦資料 時間:2019-01-01 我要投稿
【www.solarmaxlimited.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://www.solarmaxlimited.com)。

    比較奇怪的是,端口號port為啥是null,難道不是80么?

最新文章
国产v亚洲v天堂无码网站,综合亚洲欧美日韩一区二区,精品一级毛片A久久久久,欧美一级待黄大片视频
日韩中文字幕一区二区三区 | 午夜福利国产片3 | 中文字字幕在线精品乱码 | 亚洲一区二区综合婷婷 | 在线观看每日更新亚洲Av | 综合激情熟女久久 |