下面的代码几乎完美地工作。我在中间使用php从Xcode连接到本地主机上的mysql服务器。这到底会是一个登录系统:如果陈述总是去其他方法?
NSString *strURL = [NSString stringWithFormat:@"http://localhost:8888/Check.php?user=%@&pass=%@",txtName.text,passName.text];
// to execute php code
NSURLRequest *request = [NSURLRequest requestWithURL:[NSURL URLWithString:strURL]];
NSError *e;
NSData *data = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&e];
// to receive the returned value
NSString *strResult = [[[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding]autorelease];
NSLog(@"%@",strResult);
NSString *success = @"Success";
if ([strResult isEqualToString:success]) {
NSLog(@"I realize that the two strings are the same");
}
else {
NSLog(@"The two strings are not the same");
}
的strResult打印出在调试器下面,我说的是PHP文件回显到我的不同条件的项目(如用户名和密码是对还是错)
但是,由于某些原因,代码的if语句部分始终转到else方法,即使在输出中它特别指出字符串strResult包含单词“Success”。
之所以如此恼怒,因为我可以看到两个字符串,(strResult和成功),是彼此相等,但由于某些原因的Xcode不能。
如果语句不返回任何内容。 – hakre 2012-08-12 16:22:37
查看案例敏感性 – 2012-08-12 16:23:12
谢谢大家的意见。 @Codemaster Gabriel,谢谢你的建议。我希望我明白你在说什么。但是,我已经看过php文件和NSStrings的区分大小写。他们都有相同的确切“成功”作为他们的最终价值与拼写和大写相同。 – Zack 2012-08-12 16:36:12