How to post user email id & password in to JSON format i have given this information but i am getting error.
How to do this post method i want is if email & password is correct user have to enter to the next screen:
- (IBAction)enterButtonAction:(id)sender {
NSString *post =[NSString stringWithFormat:@"user[email]=%@&user[password]=%@",[userNameTF text],[passWordTF text],nil];
NSLog(@"PostData: %@",post);
NSURL *url=[NSURL URLWithString:@"http:secure.sample.in/login"];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%lu", (unsigned long)[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init] ;
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setValue:@"vz_Bim-_QYyzgJBmv68R" forHTTPHeaderField:@"authentication_token"];
[request setHTTPBody:postData];
NSURLResponse *requestResponse;
NSData *requestHandler = [NSURLConnection sendSynchronousRequest:request returningResponse:&requestResponse error:nil];
id dict = [NSJSONSerialization JSONObjectWithData:requestHandler options:0 error:nil];
NSString *id1 = [dict valueForKey:@"id"];
NSLog(@"id: %@", id1);
NSString *email = [dict valueForKey:@"email"];
NSLog(@"email: %@", email);
NSString *role = [dict valueForKey:@"role"];
NSLog(@"role: %@", role);
NSString *phone= [dict valueForKey:@"phone"];
NSLog(@"phone: %@", phone);
NSString *full_name = [dict valueForKey:@"full_name"];
NSLog(@"full_name: %@", full_name);
NSString *gender = [dict valueForKey:@"gender"];
NSLog(@"gender: %@", gender);
if (!requestResponse) {
NSLog(@"No Request");
} else {
NSLog(@"Success");
}
}