我试图通过我从php获得的结果显示NSlog
" if statement"
出于某种原因,我总是得到"无法通过POST访问PHP的消息"
如果我删除" if语句"并根据我输入的信息显示它所写的响应"成功或失败"
我做错了什么?
NSString *chklogin = [NSString stringWithFormat:@"email=%@&password=%@",usernameField.text, passwordField.text];
NSData *logindata = [NSData dataWithBytes: [chklogin UTF8String] length: [chklogin length]];
NSMutableURLRequest *urlreq = [[NSMutableURLRequest alloc] initWithURL:[NSURL URLWithString:@"http://37.142.62.22/riddem/mobileacc/userlogin.php"]];
[urlreq setHTTPMethod: @"POST"];
[urlreq setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"content-type"];
[urlreq setHTTPBody: logindata];
NSData *sendloginreq = [NSURLConnection sendSynchronousRequest:urlreq returningResponse:nil error:nil];
NSString *response =[[NSString alloc] initWithBytes:[sendloginreq bytes] length:[sendloginreq length] encoding:NSUTF8StringEncoding];
NSLog(@"%@" ,response);
if ([response isEqualToString:@"loginsecsses"]) {
NSLog(@"OK");
}
else if ([response isEqualToString:@"loginfail"]) {
NSLog(@"FAIL");
}
else { NSLog(@"Fail to access PHP via POST"); }