Skip to content

Instantly share code, notes, and snippets.

@mikeabdullah
Last active August 29, 2015 14:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mikeabdullah/d2216fdb378a71c50626 to your computer and use it in GitHub Desktop.
Save mikeabdullah/d2216fdb378a71c50626 to your computer and use it in GitHub Desktop.
Creating a Hit List URL with + symbols in query items properly encoded
- (NSURL *)hitListURLWithTaskTitle:(NSString *)title {
// Basic URL as a starting point
NSURLComponents *components = [NSURLComponents componentsWithString:@"thehitlist:///inbox/tasks"];
components.queryItems = @[
[NSURLQueryItem queryItemWithName:@"method" value:@"POST"],
[NSURLQueryItem queryItemWithName:@"title" value:title]
];
// NSURLQueryItem has encoded any spaces as %20 which is fine
// But + symbols are untouched, which will be mis-interpreted
// So post-process to encode them ourselves
components.percentEncodedQuery = [components.percentEncodedQuery
stringByReplacingOccurrencesOfString:@"+"
withString:@"%2B"];
return components.URL;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment