根据 NSURLComponents
的文档:
If you set the unencoded property, you can then obtain the encoded equivalent by reading the encoded property value and vice versa.
我试图获取查询的百分比编码版本和 url 的路径,但我错过了一些东西:
NSURL * url = [NSURL URLWithString:@"http://google.com"];
NSURLComponents * components = [[NSURLComponents alloc] initWithURL:url resolvingAgainstBaseURL:YES];
components.query = @"oauth_callback=http://google.com";
NSLog(@"Encoded: %@", [components URL]);
//-> Encoded: http://google.com?oauth_callback=http://google.com
//Does not encode "/" or ":"
我在哪里失败了?
最佳答案
我认为 NSURLComponent
的行为是正确的。
来自 Wikipedia :
In the "query" component of a URI (the part after a ? character), for example, "/" is still considered a reserved character but it normally has no reserved purpose, unless a particular URI scheme says otherwise. The character does not need to be percent-encoded when it has no reserved purpose.
关于ios - NSURLComponents 获取百分比编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25259961/