Search code examples
objective-cnsurlconnectionnsdatahttp-status-code-400

data = [NSData dataWithContentsOfURL:theUrl];


What will happen to the data object if 4xx or 5xx error take place? Does the program crash? does the data object get any kind of data (response error or corrupted data)? or the data object will be equal to nil?


Solution

  • You'll get nil back. If you want to know the reason for failure then use:

    [NSData dataWithContentsOfURL:options:error:]
    

    (reference)