我正在使用用 PHP 编写的 Web 服务来检查我的 iPhone 应用程序发送的 HTTP 请求,然后 PHP 脚本根据凭据是否正确返回是或否,目前我正在对它们进行硬编码,但它们没有t 似乎按预期运行,即使 PHP 脚本返回是,条件失败,我尝试将结果更改为硬编码字符串,这有效......
这是代码
NSString *varyingString1 = @"username=";
NSString *varyingString2 = @"username";
NSString *varyingString3 = @"&password=";
NSString *varyingString4 = @"password";
NSString *post = [NSString stringWithFormat: @"%@%@%@%@", varyingString1, varyingString2, varyingString3, varyingString4];
NSData *postData = [post dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc] init];
[request setURL:[NSURL URLWithString:@"http://url.com/api/login.php"]];
[request setHTTPMethod:@"POST"];
[request setHTTPBody:postData];
NSData *returnData = [NSURLConnection sendSynchronousRequest: request returningResponse: nil error: nil];
NSString *strResult = [[NSString alloc] initWithData:returnData encoding:NSUTF8StringEncoding];
NSString *result = strResult;
result = [post stringByReplacingOccurrencesOfString:@" " withString:@""];
if(result == @"yes"){
NSLog(@"%@",strResult);
[self performSegueWithIdentifier:@"picker" sender:self];
}else{
NSLog(@"No");
}
我用 PHP 编写的 Web 服务看起来像这样
<?php if($_POST['password'] == 'password' && $_POST['username'] == 'username') echo "yes";
else echo "no";
有任何想法吗?