你可以通过这个使用 nsurlconnection deleate 类的委托函数
(void) connection:(NSURLConnection *)connection didReceiveResponse:(NSURLResponse *)response
{
int code = [(NSHTTPURLResponse *)response statusCode];
if (code == 404)
{
// website not found
/ / do your stuff according to your need
}
}
或者在发送同步请求时,您可以检查状态代码,例如
id response2 = nil;
NSError *error1 = nil;
NSData *receivedData = [NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error1];
//and then check the above response status code like
int code = [(NSHTTPURLResponse *)response2 statusCode];
if (code == 404)
{
// website not found
/ / do your stuff according to your need
}