I need to post to this url: https://api.platform.com/media
. I am really new to HTTP request and I need to send a request that contains an image and 3 other parameters. I have the values that I need but I don't know where to begin or how it works.... Headers, Content-Length
and some other wired values.
These are the values:
media[user_profile_id]
media[channels_list][]
media[file]
Create an instance of NSURLRequest. Set the method property to POST, and set the body data.
The data needs to be a single instance of NSData, so you will have to keep appending whatever data you want to send, each field labeled and separated by ampersands like so:
id=12345&channels=1,2,3&image=123abcdef
Remember, you need to transform all strings to binary, using NSString's dataUsingEncoding: method. If you are using UIImage for the image, it has a similar method.
The server of course needs to know how to parse the data, strings being strings and the image being an image.
Finally, create an instance of NSURLConnection, set your current object as delegate and implement the delegate protocol to receive the response.
Lookup NSMutableURLRequest. You can use that with NSURLConnection.
This post should give you a better idea of how to do it.