gpt4 book ai didi

cocoa - ObjC 中的 NSURL 编码

转载 作者:行者123 更新时间:2023-12-03 16:04:21 25 4
gpt4 key购买 nike

如何在 NSURL 中进行 URL 编码?

谢谢

最佳答案

您可以使用 stringByAddingPercentEscapesUsingEncoding:

NSString* escapedUrlString =
[unescapedString stringByAddingPercentEscapesUsingEncoding:
NSUTF8StringEncoding];

但是,根据我的经验,这种方法并不是很完美(在处理一些保留字符方面),并且在很多情况下我需要使用变体:

 NSString * escapedUrlString =
(NSString *)CFURLCreateStringByAddingPercentEscapes(
NULL,
(CFStringRef)unescapedString,
NULL,
(CFStringRef)@"!*'();:@&=+$,/?%#[]",
kCFStringEncodingUTF8 );

关于cocoa - ObjC 中的 NSURL 编码,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1748981/

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