问题
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