Checking if NSURL exists

2013-08-05 Thread Koen van der Drift
How can I check if an URL on a remote server is valid and exists, without loading the website first? I tried [myURL checkResourceIsReachableAndReturnError: &error], but that always returns false, even for a very common URL such as http://www.apple.com/. That gives me @"NSCocoaErrorDomain" - cod

Re: Checking if NSURL exists

2013-08-05 Thread Koen van der Drift
After some more searching and trying out, I came up with the following: NSError *error = nil; NSHTTPURLResponse *response = nil; NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL: myURL]; [request setHTTPMethod: @"HEAD"]; NSData

Re: Checking if NSURL exists

2013-08-05 Thread Jens Alfke
On Aug 5, 2013, at 7:50 AM, Koen van der Drift wrote: > How can I check if an URL on a remote server is valid and exists, without > loading the website first? That depends on the type of URL. It sounds like you mean HTTP. Basically the answer is “you can’t” — the only way to check for existe

Re: Checking if NSURL exists

2013-08-05 Thread Jerry Krinock
As Jens explained, your does not have a clean answer. Doing a HEAD request is "optimal" (huge reduction in network traffic) if you can accept NO answers from a tiny percentage of sites which will won't return data to a HEAD request, even though they will return data to a GET.

Re: Checking if NSURL exists

2013-08-05 Thread Koen van der Drift
Thanks for all the suggestions and improvements. I will see what is the best way for my app to implement these. - Koen. On Aug 5, 2013, at 2:41 PM, Jerry Krinock wrote: > As Jens explained, your does not have a clean answer. > > Doing a HEAD request is "optimal" (huge reduction in network tr

Re: Checking if NSURL exists

2013-08-06 Thread Uli Kusterer
On Aug 5, 2013, at 8:41 PM, Jerry Krinock wrote: > As Jens explained, your does not have a clean answer. > > Doing a HEAD request is "optimal" (huge reduction in network traffic) if you > can accept NO answers from a tiny percentage of sites which will won't > return data to a HEAD request, ev