zoukankan      html  css  js  c++  java
  • 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
  • 相关阅读:
    第八周课程总结&实验报告(六)
    第七周课程总结&实验报告(五)
    第六周实验总结&学习总结
    关于我
    各种公告

    笔记 综合
    多项式全家桶
    FFT,NTT 笔记
    省选复习
  • 原文地址:https://www.cnblogs.com/sixindev/p/4800954.html
Copyright © 2011-2022 走看看