Login verification for ios
We can use the third framework AFNetworking to communicate with the server using its post method. If the userId returned by the server is 10, the operation succeeds. If the returned userId is 11, the user name or password is incorrect.
-(Void) login :( id) sender {AFHTTPRequestOperationManager * manager = [AFHTTPRequestOperationManager]; NSString * url = @ "http: // container: 8080/upload_file_service/LoginServlet"; manager. responseSerializer. acceptableContentTypes = [NSSet setWithObjects: @ "text/html", nil]; NSDictionary * namepwd =@{@ "user": @ "admin", @ "pass ": @ "123"}; [manager POST: url parameters: namepwd success: ^ (AFHTTPRequestOperation * operation, id responseObject) {NSLog (@ "post -- >%@", responseObject ); NSDictionary * datare = [[NSDictionary alloc] init]; datare = responseObject; re = [datare objectForKey: @ "userId"]; appStatus * transvalue = [appStatus ready instance]; mainViewController * mainView = [self. storyboard instantiateViewControllerWithIdentifier: @ "second"]; mainView. delegate = self; transvalue. contextStr =__ name. text; NSNumber * fre = [[NSNumber alloc] initWithInt: 10]; BOOL flag = [fre isEqualToNumber: re]; if (flag) {[self presentViewController: mainView animated: YES completion: nil] ;}} failure: ^ (AFHTTPRequestOperation * operation, NSError * error) {NSLog (@ "% @", @ "incorrect user name or password") ;}] ;}