Reputation: 107
I'm trying to use this URL in my application so that, when the user provides the right info he will be able to log in:
NSData *data = [NSData dataWithContentsOfURL: [NSURL URLWithString:[NSString stringWithFormat:@"https://www.example.come/login/CheckEligibility?json={'username'%%3A'%@'%%2C'password'%%3A'%@'}", username.text,passowrd.text]]];
For some reason I'm getting the exception:
Terminating app due to uncaught exception 'NSInvalidArgumentException', reason: 'data parameter is nil'
and when I test the URL in the browser, it works fine and gives me the data I want.
Upvotes: 0
Views: 722
Reputation: 39978
Try this
NSString *str = [NSString stringWithFormat:@"https://www.example.come/login/CheckEligibility?json={'username':'%@','password':'%@'}", username.text, passowrd.text];
str = [str stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
NSURL *url = [NSURL URLWithString:str];
NSData *data = [NSData dataWithContentsOfURL:url];
Upvotes: 2
Reputation: 8288
You need to encode the string like:
[url stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding];
Upvotes: 0