URL解析

一个URL示例https://johnny:[email protected]:443/diandi86/gogo?id=123456&name=Jack#reference
代码如下

NSString *strUlr = @"https://johnny:[email protected]:443/diandi86/gogo?id=123456&name=Jack#reference";
    self.urlLabel.text = strUlr;
    NSURL *tempUrl = [NSURL URLWithString:strUlr];
    self.schemeLabel.text = [NSString stringWithFormat:@"scheme:%@",[tempUrl scheme]];
    self.userLabel.text = [NSString stringWithFormat:@"user:%@",[tempUrl user]];
    self.passwordLabel.text = [NSString stringWithFormat:@"password:%@",[tempUrl password]];
    self.hostLabel.text = [NSString stringWithFormat:@"host:%@",[tempUrl host]];
    self.portLabel.text = [NSString stringWithFormat:@"port:%@",[tempUrl port]];
    self.pathLabel.text = [NSString stringWithFormat:@"path:%@",[tempUrl path]];
    self.queryLabel.text = [NSString stringWithFormat:@"query:%@",[tempUrl query]];
    self.fragmentLabel.text = [NSString stringWithFormat:@"fragment:%@",[tempUrl fragment]];

主界面如下

URL解析_第1张图片
1.png

点击URL解析,跳转到URL解析界面
URL解析界面如下

URL解析_第2张图片
2.png

你可能感兴趣的:(URL解析)