In an iOS app I’m trying to send a couple of files to a web server using an HTTPSocket. This is what the website says about the multipart/form-data option:
One file is in plain text, and the other is in an XML format. Both files use CRLF for end-of-lines.
This line is not part of the form. It should be one of the request headers. You can set the form contents and the header with the SetRequestContent method.
e.g.
Depending on the context it’s used in, a MIMEtype string may have a list of semicolon-delimited name=value directives after the main type/sub-type identifier. For multipart/form-data, the boundary directive is mandatory in all contexts.
[quote]
Do I need to specify Content-Type for the parts?[/quote]
Only for parts that should be interpreted as a file for upload. Such parts also include the suggested file name:
That had no effect. I’m still wondering if HTTPSocket builds the data in this format from a form. The website docs I quoted in my first post mentions input type = “file” elements. So I tried changing the data to this:
[code]
[/code]
But this still returns a 400 response. Any thoughts?
The HTTPSocket doesn’t know how to build a multipart form, you have to build it and then pass it to the socket with the SetRequestContent method (which you’re already doing.)
Shots in the dark:
Some servers require you to set a User-Agent header in the request
Some servers reject the form data if it has leading white space
Verify that the form data uses the correct end-of-line character (carriage return+line feed)
You must ensure that the boundary string does not appear anywhere in the data contained in the form