-1

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);
                                         }];
Moxy
  • 4,162
  • 2
  • 30
  • 49
Jayaprakash
  • 1,407
  • 1
  • 9
  • 19

1 Answers1

0

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.

David Rönnqvist
  • 56,267
  • 18
  • 167
  • 205
  • I mentioned 'error scenario' in the sense like 'invalid username' not like 'request fails due to server error or offline, etc'. i received the data(which contains the information(JSON) about the errors like 'errormessage') and NSError too. So i thought, the request get success, but the url response prints as 'null'. – Jayaprakash Aug 14 '13 at 04:36