您好,我正在为 iOS 编写一个 Objective-c 程序,我只想通过 ping 或对其执行 HTTP 请求来检查 smtp 服务器(在 @ 之后)是否存在并返回状态( 200 )。
我现在正在做的是获取 UITextField.text,剪切它,获取 @ 之后的子字符串并执行此操作……但它不起作用……
NSError *error = nil;
NSURL *url = [NSURL URLWithString:@"gmail.com"];
NSURLRequest *request = [NSURLRequest requestWithURL:url];;
NSURLResponse *response = nil;
NSData *data=[[NSData alloc] initWithData:[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error]];
NSString* retVal = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
// you can use retVal , ignore if you don't need.
NSInteger httpStatus = [((NSHTTPURLResponse *)response) statusCode];
NSLog(@"responsecode: %d", httpStatus);
// there will be various HTTP response code (status)
// you might concern with 404
if(httpStatus == 200)
{
NSLog(@"FEELIX CONTENT");
// do your job
}
else
{
NSLog(@"FOCK!");
}