OGeek|极客世界-中国程序员成长平台

标题: ios - NSURLComponents 获取百分比编码 [打印本页]

作者: 菜鸟教程小白    时间: 2022-12-13 00:41
标题: ios - NSURLComponents 获取百分比编码

根据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 ":"

我在哪里失败了?



Best Answer-推荐答案


我认为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/






欢迎光临 OGeek|极客世界-中国程序员成长平台 (http://sqlite.in/) Powered by Discuz! X3.4