NSURL *url = [NSURL URLWithString:@”http://www.baidu.com/search?id=1“];
2
NSLog(@”scheme:%@”, [url scheme]); //协议 http
3
NSLog(@”host:%@”, [url host]); //域名 www.baidu.com
4
NSLog(@”absoluteString:%@”, [url absoluteString]); //完整的url字符串 http://www.baidu.com:8080/search?id=1 (刚才在真机上跑了一下,并没有打印出来端口 8080 啊)
5
NSLog(@”relativePath: %@”, [url relativePath]); //相对路径 search
6
NSLog(@”port :%@”, [url port]); // 端口 8080
7
NSLog(@”path: %@”, [url path]); // 路径 search
8
NSLog(@”pathComponents:%@”, [url pathComponents]); // search
9
NSLog(@”Query:%@”, [url query]); //参数 id=1
NSURL 基本方法 absoluteString
最新推荐文章于 2025-07-30 15:20:22 发布
本文通过一个具体的NSURL实例,详细解析了其各个组成部分,包括协议、主机名、绝对字符串、相对路径、端口号、路径及参数等关键信息。
8457

被折叠的 条评论
为什么被折叠?



