NSURL组成部分详解
手思中有这么一段代码,初看下,让人摸不着头脑
//功能:UIWebView响应长按事件 -(BOOL)webView:(UIWebView *)webView shouldStartLoadWithRequest:(NSURLRequest *)request navigationType:(UIWebViewNavigationType)navigationType { if ([request URL].query){ NSArray *array = [[request URL].query componentsSeparatedByString:@"&"]; if (array.count) { for (int i = 0; i<array.count; i++) { NSString *str = [array objectAtIndex:i]; NSArray *tArray = [str componentsSeparatedByString:@"="]; DLog(@"params = %@",tArray); if (tArray.count>1){ for (int j = 0; j<tArray.count; j++) { if (j==0){ if ([[tArray objectAtIndex:j]isEqualToString:@"id"]){ NSString *idString = [tArray objectAtIndex:j+1]; NSLog(@"idString====%@",idString); } } } } } } } }
是不是,这是什么鬼。。。?
完整Url是这样的:http://183.6.151.51:8082/gwapi/news/detail?id=2776&uid=#top
[request URL].query 即为 id=2776&uid=
打印下idString为2776
之所以这样是为了获取id号,重新请求新数据
NSURL组成部分详解(原文:http://lizhuang.iteye.com/blog/1973787)
NSURL *url = [NSURL URLWithString:@"http://www.baidu.com/search?id=1"]; NSLog(@"scheme:%@", [url scheme]); //协议 http NSLog(@"host:%@", [url host]); //域名 www.baidu.com NSLog(@"absoluteString:%@", [url absoluteString]); //完整的url字符串 http://www.baidu.com:8080/search?id=1 NSLog(@"relativePath: %@", [url relativePath]); //相对路径 search NSLog(@"port :%@", [url port]); // 端口 8080 NSLog(@"path: %@", [url path]); // 路径 search NSLog(@"pathComponents:%@", [url pathComponents]); // search NSLog(@"Query:%@", [url query]); //参数 id=1
作者:SIBU iOS DEV
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.