我有一个附加密码的网络服务 url。当我通过提供正确的密码运行应用程序时,应用程序正在运行,同时我使用错误的凭据运行应用程序。该应用程序正在运行,我不知道摆脱这个问题。我的代码在这里:
NSString *post =[[NSString alloc] initWithFormat:@"password=%@",[password text]];
NSLog(@"PostData: %@",post);
NSURL *url=[NSURL URLWithString:[NSString stringWithFormat:@"http://myexample.com/Accountservice/Secure/ValidateAccess?password=abcd&type=1"]];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/json" forHTTPHeaderField:@"Accept"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLRequest *request1 = [[NSURLRequest alloc] initWithURL:[NSURL URLWithString:post] cachePolicy:NSURLRequestReloadIgnoringLocalCacheData timeoutInterval:10];
NSURLConnection *connection = [[NSURLConnection alloc] initWithRequest:request1 delegate:self startImmediately:YES];
if(!connection){
NSLog(@"connection failed");
}
else{
NSLog(@"connection succeeded");
}
如果我给了'abcd'作为密码连接成功显示。如果我给出了错误的密码连接成功显示。我该如何解决这个问题?如果我输入了错误的密码,需要显示警报。