NSURLConnection sendAsynchronousRequest returning null response in error scenario

578 views Asked by At

When i send a async request using the sendAsynchronousRequest method, it returns the null response in the error scenario like 'invalid username'. In the API, i am sending the response, at error scenario with corresponding JSON values.

It receives the JSON, but url response is null.

It works fine when i do this in connectionWithRequest: method with proper delegate methods.

Any help would be much appreciated.

Thanks!

[NSURLConnection sendAsynchronousRequest:request 
                                   queue:[[NSOperationQueue alloc] init] 
                       completionHandler:^(NSURLResponse *response, NSData *data, NSError *error) {
                                             NSLog(@"%@", (NSHTTPURLResponse *)response);
                                         }];
1

There are 1 answers

1
David Rönnqvist On

What you are seeing is the expected behaviour.

Straight from the documentation of said method:

If the request fails, the data parameter is nil and the error parameter contain information about the failure.