On Thu, Feb 17, 2011 at 3:50 PM, Jeroen De Dauw <jeroendedauw(a)gmail.com>wrote;wrote:
The documentation states very helpful "When
uploading files directly, the
request must use multipart/form-data as Content-Type or enctype,
application/x-www-form-urlencoded will not work.", but then provides no
clue
at how to actually set the content type when making a request via the
MWHttpRequest class. I tried several things after looking at the source,
but
could not get it working. Also am not finding any existing code doing this.
Not sure you can at the moment... PhpHttpRequest forces the Content-Type
header to application/x-www-form-urlencoded. CurlHttpRequest doesn't seem
to, but offhand I don't know whether it knows how to do multipart encoding
automatically from key-value pairs as the post data if you set the
Content-Type header manually.
Those classes probably need a little tweaking to support multipart.
(Some quick background: HTML forms can be submitted using either
'application/x-www-form-urlencoded' style which basically just shoves a
query-string into the POST body instead of on the URL -- or
'multipart/form-data' which uses a variant of MIME multipart document
structure to list key-value pairs with additional metadata like type, size,
optional filenames etc. File upload controls are the only thing in regular
HTML forms that require the multipart system, and the PHP infrastructure
will only slurp in files if they're provided that way. At the HTTP client
level, the difference between the two is only in the HTTP 'Content-Type'
header and the formatting of the POST body contents. Libraries like CURL
sometimes provide handy methods to do the formatting for you from arrays of
key-value pairs.)
-- brion