下面的代碼幾乎完美地工作。我在中間使用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