开发者

Way to build a querystring in obj-c that escapes as necessary?

I want to build a querystring in obj-c eg http://myurl.com/myservice?key=value&key2=value2

Just wondering how to go abo开发者_JAVA技巧ut doing this so that all the unfriendly characters (eg &, %) get escaped properly?

Thanks


Will this work?

+(NSString*)urlEscape:(NSString *)unencodedString {
    NSString *s = (NSString *)CFURLCreateStringByAddingPercentEscapes(NULL,
        (CFStringRef)unencodedString,
        NULL,
        (CFStringRef)@"!*'\"();:@&=+$,/?%#[]% ",
        kCFStringEncodingUTF8);
    return [s autorelease]; // Due to the 'create rule' we own the above and must autorelease it
}
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜