如何检查iOS中的Web服务器的状态?

我需要检查Web服务器的状态,具体来说,如果Web服务器返回正确的状态代码200的信息。有什么办法从iOS的Web服务器获取HTTP响应代码?

这在官方文档中有详细logging ,不需要实现第三方库(尽pipe如果你是iOS编程的新手,一个networkingAPI可以简化底层的函数调用)。 你的类必须是一个NSURLConnection委托,并在NSURLConnection之后实现委托方法是这样的:

-(void)connection:(NSURLConnection *)connection didReceiveResponse:(NSHTTPURLResponse*)response { if ([response statusCode] == 200) { // Handle valid response (You can probably just let the connection continue) } else { // Other status code logic here (perhaps cancel the NSURLConnection and show error) } } 

您应该在iOS上findURL加载指南非常有用的阅读这个和其他networkingfunction。