Check web server is up or down in iphone
I need a little help here!!!
If string 'url' contains the address to web server, how do i check whether my web server is up or down? I got some codes to check Internet connectivity. But even if we have internet connectivity how do we know server is up or开发者_运维百科 not? Is there any better way to do that?
Thank You
You could do a request,
NSURLRequest *theRequest=[NSURLRequest requestWithURL:[NSURL URLWithString:url]
cachePolicy:NSURLRequestUseProtocolCachePolicy
timeoutInterval:20.0];
NSURLConnection *theConnection=[[NSURLConnection alloc] initWithRequest:theRequest
delegate:self];
Now if you implement (along with all other delegate methods)
-(void)connectionDidFinishLoading:(NSURLConnection *)connection
-(void)connection:(NSURLConnection *)connection didFailWithError:(NSError *)error
you will get either succes or error.
Post a request, get the response. If you get a response, the server is up, if not its down..
精彩评论