iOS中NSURL常用屬性

 

    NSString *urlstr = @"http://api.test.com:8080/index.php?g=api&m=base&a=skyuv&city=110229";
    NSURL *url = [NSURL URLWithString:urlstr];
    NSLog(@"scheme:%@", url.scheme);                    //協議 http
    NSLog(@"host:%@", url.host);                        //域名 api.test.com
    NSLog(@"absoluteString:%@", url.absoluteString);    //完整的url字符串
    NSLog(@"relativePath: %@", url.relativePath);       //相對路徑 /index.php
    NSLog(@"port :%@", url.port);                       //端口 8080
    NSLog(@"path: %@", url.path);                       //路徑 /index.php
    NSLog(@"pathComponents:%@", url.pathComponents);    //("/","index.php")
    NSLog(@"Query:%@", url.query);                      //參數 g=api&m=base&a=skyuv&city=110229

 

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章