I\'ve got to send a https GET request to a web service in my iPhone app which is developing in Swift 1.2.
I am trying to construct query string parameters but got to
I used such an utility method to URL-encode values in GET-requests:
@interface NSString (Ext)
@property (nonatomic, readonly) NSString *urlEncoded;
@end
@implementation NSString (Ext)
- (NSString *)urlEncoded {
NSMutableCharacterSet *const allowedCharacterSet = [NSCharacterSet URLQueryAllowedCharacterSet].mutableCopy;
// See https://en.wikipedia.org/wiki/Percent-encoding
[allowedCharacterSet removeCharactersInString:@"!*'();:@&=+$,/?#[]"]; // RFC 3986 section 2.2 Reserved Characters (January 2005)
NSString *const urlEncoded = [self stringByAddingPercentEncodingWithAllowedCharacters:allowedCharacterSet];
return urlEncoded;
}
@end