鸟语天空
NSURL类
post by:追风剑情 2019-3-6 11:25

通过URL读取数据

示例

#import <Foundation/Foundation.h>

int main(int argc, const char * argv[]) {
    @autoreleasepool {
        NSURL *myURL = [NSURL URLWithString: @"http://www.baidu.com"];
        
        // 读取百度首页的html内容
        NSString *myHomePage = [NSString stringWithContentsOfURL:
            myURL encoding: NSASCIIStringEncoding error: NULL];
        
        NSLog(@"%@", myHomePage);
        
        // 从URL读取字典
        //myURL = [NSDictionary dictionaryWithContentsOfURL: myURL];
        // 从URL读取数组
        //myURL = [NSArray arrayWithContentsOfURL: myURL];
        // 从URL读取任意数据
        //myURL = [NSData dataWithContentsOfURL: myURL options: NSDataReadingUncached error: NULL];
    }
    return 0;
}

运行测试
111.png

评论:
发表评论:
昵称

邮件地址 (选填)

个人主页 (选填)

内容