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
}
精彩评论