I have successfully made a PHP REST webservice for my iphone app. Below is the code with the url request, which works at the moment. My question is:
How do I convert this to send a username with the request, so i can fetch a single user and not just all users?
I think I need to do a POST or something. I have tried for hours but cannot get anything to work. And how do I fetch the POST data from my PHP web service? I assume it's not just as simple as _POST?
I am totally lost on this problem, any help is appreciated.
User *newUser = [[User alloc] init];
NSURL *url = [NSURL URLWithString:@"http://photoapp.steffenamby.dk/REST/userbyusername"];
NSURLRequest *urlRequest = [NSURLRequest requestWithURL:url];
NSURLResponse *response = nil;
NSError *error = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:urlRequest
returningResponse:&response
error:&error];
if(data.length > 0 && error == nil){
NSDictionary *userdata = [NSJSONSerialization JSONObjectWithData:data options:0 error:NULL];
[newUser setUserid:[[userdata objectForKey:@"id"] intValue]];
[newUser setUsername:username];
[newUser setAge: [[userdata objectForKey:@"age"] intValue]];
[newUser setFirstname:[userdata objectForKey:@"firstname"]];
[newUser setLastname:[userdata objectForKey:@"lastname"]];
[newUser setEmail:[userdata objectForKey:@"email"]];
}