I’m trying to make a POST request, and I can’t seem to figure out what is going wrong. I am getting a response back from the server, but my email/password pair doesn’t seem to be being sent/read properly (by the server) and it tells me that no such account exists.
Here’s my code that is contained within a function (which is called when the user presses a “login” button I have created). Note: the variables ’email’ and ‘password’ are set to the values in 2 textfields I have also created.
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];
}
Can anyone see anything wrong with my logic?
You’re adding a
Current-Typeheader (which AFAIK is not even a valid header) instead ofContent-Type.