I am making a HTTP call to the server using the POST method.When the register button is clicked am calling the service as given below
NSURL * url=[NSURL URLWithString:[NSString stringWithFormat:@"http://offers2win.com/api/v1/users?user[email]=%@&user[password]=%@&user[password_confirmation]=%@",username,password,confirmpassword]];
request = [NSMutableURLRequest requestWithURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/json" forHTTPHeaderField:@"Content-Type"];
connection=[[NSURLConnection alloc] initWithRequest:request delegate:self];
And saving the responde data in the dictionary
NSData *responseData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&err];
returnString = [[NSString alloc] initWithData:responseData encoding:NSUTF8StringEncoding];
NSDictionary *dictionary = [NSJSONSerialization JSONObjectWithData:[returnString dataUsingEncoding:NSUTF8StringEncoding] options:kNilOptions error:nil];
But the delegate is called twice
- (void)connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
NSLog(@"Recieved");
}
What could be the reason?And also it is taking a long time to get the response.
This is not error. Apple has already told about this in NSURLConnectionDataDelegate Protocol Reference:
Check Here : NSURLConnectionDataDelegate Protocol Reference