如何在iPhone中的URL中发送多个帖子数据
目前我知道我可以通过 HTTP 请求将 post 数据发送到 URL。有没有办法通过 HTTP 请求发送附加到 URL 的多个帖子数据。我知道我可以发送 POST 数据,因为我一直在这样做,但不知道如何附加多个帖子数据。 下面是我的单个帖子的代码。有没有办法将另一个 NSString key2 添加到 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];
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];
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
您可以扩展它
并添加更多由 &s 分隔的键值对,如下所示
You can extend this
and add more key value pairs separated by &s, like this