NSUrl读取网络资源
2016-02-03 22:07
323 查看
#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为:https
2016-02-03 22:02:05.528 NSUrl[838:26688] url的hostwww.baidu.com
2016-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>
相关文章推荐
- lighttpd-1.4.39 : array
- Could not find artifact plugin:jar in nexus http://localhost:8081/nexus/content/groups/public
- C#中HttpWebRequest的GetRequestStream执行的效率太低,甚至偶尔死掉
- 【slighttpd】基于lighttpd架构的Server项目实战(1)—前言及设计思路
- linux 网络命令整理
- HTTP1.1协议中文版-RFC2616
- AFNetworking3.0网络请求方法封装(自带缓存功能)
- Python实现NN(神经网络)
- cinder list 报错:ERROR: Malformed request url (HTTP 400)
- 使用HttpURLConnection查看图片
- 广西首届网络安全选拔赛PWN、REVERSE、决赛题目
- nyoj 489
- 广西首届网络安全选拔赛 MISC Wirteup
- 广西首届网络安全选拔赛 WEB Writeup
- 从Http协议报头看RESTful
- 百行代码教你了解何为神经网络
- HttpClient_4 用法(HC3-->HC4必看)
- Ios9下访问http:// 安全认证
- Linux TCP队列相关参数的总结
- Python 14.2 TCP编程