gpt4 book ai didi

ios - NSURLComponents 获取百分比编码

转载 作者:塔克拉玛干 更新时间:2023-11-02 21:21:35 24 4
gpt4 key购买 nike

根据 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/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com