你好,我正在爲objective-c爲iOS做一個程序,我想只檢查smtp服務器(@之後)是否存在通過ping它或做一個HTTP請求,並得到狀態(200 )。如何檢查smtp服務器(如gmail.com/hotmail.fr)是否存在?
我在做什麼現在它得到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!");
}
您想要將端口80上的HTTP與端口20上運行的SMTP服務器交談?我建議你去學習TCP/IP。 – mattjgalloway
你爲什麼要檢查一個SMTP服務器是否存在?你想解決什麼問題? – CodeCaster