My iOS app downloads document files from a server using the NSURLConnection
class. I use it asynchronously.
It can happen that a document is missing from the server (configuration error). I expected NSURLConnection
to call my delegate error method:
- (void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
But it doesn't. Instead, it happily downloads the HTML error 404 web page returned by the server. The only workaround I found was to check the NSURLResponse
MIMEtype
property and fail myself when it is text/html
. It works fine, but I don't like it because it precludes me from supporting html documents at a later date.
How can I check whether a requested URL is indeed present on the server?
Thanks