开发者

How to send multiple post data in URL in iphone

Currently I know I can send post data to URL through HTTP request. Is there a way to send multiple post data attached to the URL through HTTP request. I know for the fact that I can send POST data since I have been doing it but no idea on how to append multiple post data. Below is my code for single post. Is there a way to add another NSString key2 to the URL ?

NSString *initialURL = [NSString stringWithFormat:@"http://www.abc.com"];
NSURL *url=[NSURL URLWithString:initialURL];

NSString *key = [NSString stringWithFormat:@"key=%@", keyValue];
NSData *mastData = [key dataUsingEncoding:NSUTF8StringEncoding allowLossyConversion:YES];
NSString *mastLength = [NSString stringWithFormat:@"%d",[mastData length]];

NSMutableURLRequest *request = [[[NSMutableURLRequest alloc] init] autorelease];
[request setURL:url];
[request setHTTPMethod:@"POST"];
[request setValue:mastLength forHTTPHeaderField:@"Content-Length"];
[request开发者_如何学运维 setValue:@"application/x-www-form-urlencoded" forHTTPHeaderField:@"Content-Type"];
[request setHTTPBody:mastData];


You can extend this

NSString *key = [NSString stringWithFormat:@"key=%@", keyValue];

and add more key value pairs separated by &s, like this

NSString *key = [NSString stringWithFormat:@"key=%@&key2=%2", keyValue, key2value];
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜