Skip to content

Commit

Permalink
URL encode paramaters sent with CS request.
Browse files Browse the repository at this point in the history
  • Loading branch information
Alex Olson committed Jan 10, 2011
1 parent 9b47216 commit ac29434
Show file tree
Hide file tree
Showing 3 changed files with 7 additions and 5 deletions.
5 changes: 3 additions & 2 deletions Examples/CocoaApp/Kynetx.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ - (NSURL*) URLFromDict:(NSDictionary*)params withBaseURL:(NSString*)URLstring {
NSArray* keys = [params allKeys];
int count = [keys count];
for (int i = 0; i < count; i++) {
id key = [keys objectAtIndex:i];
id value = [params objectForKey:key];
id key = [[keys objectAtIndex:i] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
id value = [[params objectForKey:key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if (i != count - 1) {
[buildString appendFormat:@"%@=%@&",key,value];
} else {
[buildString appendFormat:@"%@=%@",key,value];
}
NSLog(@"KEY: %@ VALUE: %@", key, value);
}

// at this point, URL is now constructed and ready to be returned
Expand Down
2 changes: 1 addition & 1 deletion Examples/CocoaApp/MainWindowController.m
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ @implementation MainWindowController

- (IBAction) sendTestKynetx:(id) sender {
[self setApp:[[[Kynetx alloc] initWithAppID:[appIDField stringValue] eventDomain:@"mobile" delegate:self] autorelease]];
NSDictionary* urlParams = [NSDictionary dictionaryWithObjectsAndKeys:@"bar", @"foo", @"whiz", @"cheese", nil];
NSDictionary* urlParams = [NSDictionary dictionaryWithObjectsAndKeys:@"bar", @"foo", @"whiz", @"cheese&whiz", nil];
[app signal:@"jump_for_joy" params:urlParams];
}

Expand Down
5 changes: 3 additions & 2 deletions kynetx.m
Original file line number Diff line number Diff line change
Expand Up @@ -147,13 +147,14 @@ - (NSURL*) URLFromDict:(NSDictionary*)params withBaseURL:(NSString*)URLstring {
NSArray* keys = [params allKeys];
int count = [keys count];
for (int i = 0; i < count; i++) {
id key = [keys objectAtIndex:i];
id value = [params objectForKey:key];
id key = [[keys objectAtIndex:i] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
id value = [[params objectForKey:key] stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
if (i != count - 1) {
[buildString appendFormat:@"%@=%@&",key,value];
} else {
[buildString appendFormat:@"%@=%@",key,value];
}
NSLog(@"KEY: %@ VALUE: %@", key, value);
}

// at this point, URL is now constructed and ready to be returned
Expand Down

0 comments on commit ac29434

Please sign in to comment.