0

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!

Chris
  • 11,819
  • 19
  • 91
  • 145

1 Answers1

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"];
Anton
  • 2,342
  • 15
  • 17
  • So if I have like 15 items in the dictionary, a loop would probably be best? Also, once request is properly filled, how do I send it? – Chris May 29 '11 at 22:00
  • @Chris Everything's in the docs. Either set a delegate and use startAsynchronous or startSynchronous if you really need it. – Anton May 30 '11 at 10:34
  • I've been trying to get this ASI thing to work and it is aweful. It is incomplete on download and then you add this GHUnit set of classes that have added 67 errors to work through about not having the right files. Good God, any other way to do this? – Chris May 30 '11 at 13:34
  • @Chris you can always use NSURLConnection: for example, look at http://www.deanoj.co.uk/ios-development/making-a-http-post-request-with-nsurlconnection/ – Anton May 30 '11 at 19:13