0
我有下面的代码运行良好,但似乎没有发布任何东西,或者至少我的PHP没有拿起它。我究竟做错了什么?HTTP发布在objective-c不发布任何东西
这里是我的PHP:
$usr = $_POST['username'];
$psw = $_POST['password'];
if ($usr == '1' && $psw == '1') {
echo 'Yes';
}
这是我的目标c
NSString *post =[NSString stringWithFormat:@"username=%@&password=%@",usernameField.text, passwordField.text];
NSString *hostStr = @"http://ep.samico.dk/blogapp/login.php?";
hostStr = [hostStr stringByAppendingString:post];
NSData *dataURL = [NSData dataWithContentsOfURL: [ NSURL URLWithString: hostStr ]];
NSString *serverOutput = [[NSString alloc] initWithData:dataURL encoding: NSASCIIStringEncoding];
if([serverOutput isEqualToString:@"Yes"]){
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"success" message:@"You are authorized"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertsuccess show];
} else {
UIAlertView *alertsuccess = [[UIAlertView alloc] initWithTitle:@"Fail" message:@"Invalid Access"
delegate:self cancelButtonTitle:@"No" otherButtonTitles:@"Yes", nil];
[alertsuccess show];
}
变化的响应只是'的print_r($ _ POST);',看看它返回。 – 2012-01-18 17:37:13
我猜你实际上正在格式化GET请求而不是发布。 – 2012-01-18 17:39:32
或'var_dump($ _ POST);'tomato - tomahto。 – rdlowrey 2012-01-18 17:41:14