Hello i'm making a program in objective-c for iOS, i would like to only check if the smtp server ( after the @ ) exists by ping it or doing a HTTP request on it and get in return the status ( 200 ).
what i'm doing now it's getting the UITextField.text, cutting it, getting the substring after the @ and doing this... but it is not working...
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!");
}