我正在尝试将我的textfields firstname和lastname的内容与我的按钮发送到我的php服务器。一旦我运行我的应用程序并用一些随机文本填充我的文本字段并按发送,我在我的服务器上收到一封电子邮件,但没有内容。
(void) sendAction{
NSError *error = nil;
NSString *postparams = [NSString stringWithFormat:@"info=%@_%@",firstname.text,lastname.text];
NSData * postdata = [postparams dataUsingEncoding:NSASCIIStringEncoding allowLossyConversion:YES];
NSString * postlength= [NSString stringWithFormat:@"%d",[postdata length]];
NSMutableURLRequest *request = [[NSMutableURLRequest alloc]init];
[request setURL:[NSURL URLWithString:@"http://faketest.com/test/mail.php"]];
[request setHTTPMethod:@"POST"];
[request setValue:postlength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Current-Type"];
[request setHTTPBody:postdata];
NSData * rawdata = [NSURLConnection sendSynchronousRequest:request returningResponse:nil error:&error];
NSString *rawdatastring =[[NSString alloc]initWithData:rawdata encoding:NSUTF8StringEncoding];
NSLog(@"%@",rawdatastring);
}
答案 0 :(得分:0)
我相信这可能是因为您使用的是“Current-Type”标头,而不是通常的“Content-Type”标头。尝试以下操作,看看它是否解决了问题:
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];