如何在Objective-C中通过http POST发送NSMutableDictionary [英] How to send NSMutableDictionary via http POST in Objective-C

查看:222
本文介绍了如何在Objective-C中通过http POST发送NSMutableDictionary的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个带有一些歌曲数据的NSMutableDictionary(例如key:Artist对象:Passion Pit),我需要将其作为http POST变量发送到服务器。我一整天都在阅读示例,无法弄清楚如何转换字典的值和键,然后将它们发送到URL。

I have an NSMutableDictionary with some song data (for example key: "Artist" object: "Passion Pit") that I need to send to a server as http POST variables. I have been reading examples all day and cannot figure out how to convert my dictionary's values and keys and then send them to a URL.

iPhone SDK是否为您提供了一种方法这样做或者是否有我应该下载的源代码?

Does the iPhone SDK give you a means of doing that or is there source code that I should be downloading?

感谢您的帮助!

推荐答案

最简单的解决方案是使用 ASIHTTPRequest 库。以下是文档中的示例:

The easiest solution is to use the ASIHTTPRequest library. Here's an example from documentation:

ASIFormDataRequest *request = [ASIFormDataRequest requestWithURL:url];
[request setPostValue:@"Ben" forKey:@"first_name"];
[request setPostValue:@"Copsey" forKey:@"last_name"];
[request setFile:@"/Users/ben/Desktop/ben.jpg" forKey:@"photo"];

这篇关于如何在Objective-C中通过http POST发送NSMutableDictionary的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆