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
  • 相关阅读:
    hdu 2842 Chinese Rings
    Codeforces Round #118 (Div. 1) A 矩阵快速幂
    hdu2604 Queuing
    支付宝 生活号 获取 userId 和 生活号支付
    maven 项目使用本地jar
    nexus 私有 maven 仓库的搭建
    linux jdk 安装
    gitlab 可以上传代码,但是 不能 上传 tag 问题
    maven 内置变量
    mysql 不允许分组的问题 this is incompatible with sql_mode=only_full_group_by
  • 原文地址:https://www.cnblogs.com/sixindev/p/4800954.html
Copyright © 2011-2022 走看看