URI encoding need to be done when performing network API calls based on RFC 3986. In order to encode any character, the following native method can be used:
[uriString stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet URLQueryAllowedCharacterSet]]
But the above method is not compliant with RFC3986 and it does not encode the reserved characters like "!*'();:@&=+$,/?%#[]". Hence, the following method can be used for percent encoding the specific reserved characters.
[uriString stringByAddingPercentEncodingWithAllowedCharacters:
[NSCharacterSet URLQueryAllowedCharacterSet]]
But the above method is not compliant with RFC3986 and it does not encode the reserved characters like "!*'();:@&=+$,/?%#[]". Hence, the following method can be used for percent encoding the specific reserved characters.
((NSString *)CFBridgingRelease(CFURLCreateStringByAddingPercentEscapes(NULL, (__bridge CFStringRef) string, NULL, CFSTR("!*'();:@&=+$,/?%#[]"), encoding)));
}
Comments
Post a Comment