NSUrl读取网络资源
来源:互联网 发布:网络直销流程五步 编辑:程序博客网 时间:2024/05/23 01:15
#import "ViewController.h"@interface ViewController ()@end@implementation ViewController- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. NSURL *url = [NSURL URLWithString:@"https://www.baidu.com"]; NSLog(@"url的scheme为:%@",[url scheme]); NSLog(@"url的host%@",[url host]); NSLog(@"url的port%@",[url port]); NSLog(@"url的path为%@",[url path]); //使用URL对应的资源初始化NSString NSString *baidu = [NSString stringWithContentsOfURL:url encoding:NSUTF8StringEncoding error:nil];//输出NSString 即可看到页面的源代码 NSLog(@"%@",baidu);}- (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated.}@end
输出为:
2016-02-03 22:02:05.527 NSUrl[838:26688] url的scheme为:https2016-02-03 22:02:05.528 NSUrl[838:26688] url的hostwww.baidu.com2016-02-03 22:02:05.528 NSUrl[838:26688] url的port(null)2016-02-03 22:02:05.528 NSUrl[838:26688] url的path为2016-02-03 22:02:17.546 NSUrl[838:26688] <html><head><script>location.replace(location.href.replace("https://","http://"));</script></head><body><noscript><meta http-equiv="refresh" content="0;url=http://www.baidu.com/"></noscript></body></html>
3 0
- NSUrl读取网络资源
- Objective-C 根据NSURL读取网络资源
- Android读取网络资源
- 使用URL读取网络资源
- 使用URL读取网络资源
- 使用 URL 读取网络资源
- scala 读取网络资源
- URL读取网络资源openStream
- NSURL
- NSURL
- NSURL
- NSURL
- NSURL
- NSURL
- NSURL
- NSURL
- NSURL
- NSURL
- False Positives和False Negative等含义
- 预览Android layouts, custom views和animations的插件
- 分享一个链接
- data too long for column 'name' at row 1的解决办法
- leetcode笔记:Majority Element
- NSUrl读取网络资源
- Androidx学习笔记(44)--- 多线程断点续传(Android项目)
- 开启QtCreator的代码自动补全功能
- log4j【1】(使用xml还是使用properties)
- [剑指offer-1385]重建二叉树
- 字符串反转的7种方式
- log4j【2】(Category与Logger )
- JAVA面试题
- 文章地址2\3