iPhone中POST方法的多参数 [英] Multiple Parameter for POST Method in iPhone
本文介绍了iPhone中POST方法的多参数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在尝试使用POST将多个参数发送到特定的url.但是它没有正确发送参数.
I am trying to send multiple parameter to specific url with POST. But it is not sending the Parameter properly.
NSDate *now = [ NSDate date];
NSDateFormatter *formatter = [[NSDateFormatter alloc] init];
[formatter setDateFormat:@"MM/dd/YY HH:mm:ss"];
NSString *startDateTime = [formatter stringFromDate:now];
NSMutableString *URL=[[[NSMutableString alloc] initWithString:LIVE_CHAT_URL] autorelease];
NSMutableURLRequest *request = [NSMutableURLRequest requestWithURL:[NSURL URLWithString:URL]];
NSString *postData = [[NSString alloc] initWithFormat:@"Message=%@&MethodName=AddMessage&ToUserLoginId=18&StartTime=%@&Language=en&userID=%d",field.text,startDateTime,1];
NSString *postLength = [NSString stringWithFormat:@"%d", [postData length]];
NSLog(@"post:%@",postData);
[request setHTTPMethod:@"POST"];
[request setValue:postLength forHTTPHeaderField:@"Content-Length"];
[request setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:[postData dataUsingEncoding:NSUTF8StringEncoding]];
[postData release];
[postLength release];
[formatter release];
NSError *error;
NSURLResponse *response;
NSData *urlData=[NSURLConnection sendSynchronousRequest:request returningResponse:&response error:&error];
NSString *data=[[NSString alloc]initWithData:urlData encoding:NSUTF8StringEncoding];
推荐答案
我这里有一个完整的POST示例,其中包含动态联系表单ViewController:
I have a complete POST example with a dynamic contact form ViewController here:
https://github.com/mikecheckDev/MDContactForm
这篇关于iPhone中POST方法的多参数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文