How to send NSMutableDictionary via http POST in Objective-C

会有一股神秘感。 提交于 2019-12-13 03:09:18

问题


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.

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

Thanks for the help!


回答1:


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"];


来源:https://stackoverflow.com/questions/6170166/how-to-send-nsmutabledictionary-via-http-post-in-objective-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!