NSURL *url = [NSURL URLWithString:@"http://example.com/v1"];
NSLog(@"%@",url);
NSURL *newURL = [NSURL URLWithString:@"foo?bar=baz" relativeToURL:url];
NSLog(@"newURL:%@",[newURL absoluteString]);
打印结果:
http://example.com/foo?bar=baz------------>v1被替换掉了哦T T
解决办法
url = [url URLByAppendingPathComponent:@""];// 会加上 /
NSLog(@"****url:%@",[url absoluteString]);//---->http://example.com/v1/
newURL = [NSURL URLWithString:@"foo?bar=baz" relativeToURL:url];
NSLog(@"====newURL:%@",[newURL absoluteString]);
打印结果:
http://example.com/v1/foo?bar=baz
网友评论