我正在尝试发出 POST 请求,但我似乎无法弄清楚出了什么问题。我从服务器收到回复,但我的电子邮件/密码对似乎没有被正确发送/读取(由服务器),它告诉我不存在这样的帐户。
这是包含在函数中的代码(当用户按下我创建的“登录”按钮时调用)。注意:变量“电子邮件”和“密码”设置为我还创建的 2 个文本字段中的值。
NSURL *url = [NSURL URLWithString:@"http://mydomain.com/login-ipad/"];
NSMutableURLRequest *theRequest = [NSMutableURLRequest requestWithURL:url];
NSString *messageBody = [NSString stringWithFormat:@"email=%@&user_pass=%@",email,password];
NSString *msgLength = [NSString stringWithFormat:@"%d", [messageBody length]];
[theRequest addValue: @"text/xml; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
[theRequest setHTTPMethod:@"POST"];
[theRequest addValue: msgLength forHTTPHeaderField:@"Content-Length"];
[theRequest setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[theRequest setHTTPBody:[messageBody dataUsingEncoding:NSUTF8StringEncoding]];
NSURLConnection *theConnection = [[NSURLConnection alloc] initWithRequest:theRequest delegate:self];
if(theConnection)
{
NSLog(@"Connection Successful");
parent.loginButton.enabled = NO;
receivedData = [[NSMutableData data] retain];
}
else
{
UIAlertView *alert1 = [[[UIAlertView alloc] initWithTitle:@"Alert" message:@"There was an issue sending the data. Please check your internet connection." delegate:self cancelButtonTitle:@"OK" otherButtonTitles:nil] autorelease];
[alert1 show];
}
有人能看出我的逻辑有什么问题吗?