Search code examples
iphonecocoa-touchnsurlconnectionnsfilemanager

Check if file on website exists


on the iPhone I want to check, if a specific file (test.licence) on a website exsists. My approach (so far) was to download the file and check if it exists in my Documents directory. However, if the file does not exists, Apache presents a HTML error page (which I download instead of test.licence). Checking the file size is a fuzzy solution, since it varies.

So, how do I check, if a online file exists (not more)? I'm looking for a simple yet clean solution.

Regards,

Stefan


Solution

  • Submit an NSURLRequest via NSURLConnection. When you receive a response, check whether the status code is 200 (it's there), 404 (it's not) or something else (a different thing happened).