简体   繁体   中英

How to check if a .html page is reachable via iPhone 4?

I have the following problem: I want to check if a website (in a deeper directory for example Foo/bar/xy.html ) is reachable. So I have already tried out the "SystemConfiguration Framework" with Apple's "reachable" example, but I'm just able to get to the host and not to the specific html page. Has anyone an idea, how a check of a html side (a short example would be nice) could be done with the iPhone?

Thank you and best regards!

The reachable API only does host from my understanding. I might recommend you do a head request to the page and see what the response code is. If it returns 404 then it failed to find the page.

quick example:

NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:url];  
[request setHTTPMethod:@"HEAD"];  
NSHTTPURLResponse *response;  
[NSURLConnection sendSynchronousRequest:request returningResponse:&response error: NULL];
 if([response statusCode] == 404)
    //failed to find page  

Note: I did not test this code but concept should make sense.

also http HEAD info:

http://www.w3.org/Protocols/rfc2616/rfc2616-sec9.html

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM