我遇到了$ _POST方法的问题。我使用此代码通过OBJ-C发送它:
NSString *postRegistration = [NSString stringWithFormat:@"username=%@&password=%@",usernameLog, passwordLog];
NSData *postData = [postRegistration dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString *postLength = [NSString stringWithFormat:@"%d",[postData length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:[NSURL URLWithString:[NSString stringWithFormat:@"myurl"]]];
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:postData];
NSURLConnection *conn = [[NSURLConnection alloc]initWithRequest:request delegate:self];
并尝试在PHP中使用它
$username = $_POST['username'];
$array = array($username);
echo json_encode($array);
我一直都是空的。我查了一下,用json一切都还好。所以POST方法肯定有问题。