I want to make a POST
request in my app. I use the following code:
NSString *post = [NSString stringWithFormat:@"Email=%@&Password=%@",self.emailTxt.text,self.pwTxt.text];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:kEmailLogin]];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSError *error = [[NSError alloc] init];
NSHTTPURLResponse *responseCode = nil;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:&responseCode error:&error];
When I run this with the simulator with an iOS 9 device it works perfectly. But in my iPad with iOS X it crashes every time I perform the request.
How should I do the POST
request to make it work in a iOS X device?
kEmailLogin
is a variable with a HTTPS
url for a service that returns a JSON
.