Hmm.. Yes, it looks like it just needs a minor tweak:
static void createHeadersAndPostData (const URL& url, String& headers, MemoryBlock& postData)
{
MemoryOutputStream data (postData, false);
data << getMangledParameters (url);
if (url.getFilesToUpload().size() > 0)
{
// need to upload some files, so do it as multi-part...
const String boundary (String::toHexString (Random::getSystemRandom().nextInt64()));
headers << "Content-Type: multipart/form-data; boundary=" << boundary << "\r\n";
data << "--" << boundary;
for (int i = 0; i < url.getParameterNames().size(); ++i)
{
data << "\r\nContent-Disposition: form-data; name=\""
<< url.getParameterNames() [i]
<< "\"\r\n\r\n"
<< url.getParameterValues() [i]
<< "\r\n--"
<< boundary;
}
for (int i = 0; i < url.getFilesToUpload().size(); ++i)
{
const File file (url.getFilesToUpload().getAllValues() [i]);
const String paramName (url.getFilesToUpload().getAllKeys() [i]);
data << "\r\nContent-Disposition: form-data; name=\"" << paramName
<< "\"; filename=\"" << file.getFileName() << "\"\r\n";
const String mimeType (url.getMimeTypesOfUploadFiles()
.getValue (paramName, String()));
if (mimeType.isNotEmpty())
data << "Content-Type: " << mimeType << "\r\n";
data << "Content-Transfer-Encoding: binary\r\n\r\n"
<< file << "\r\n--" << boundary;
}
data << "--\r\n";
}
else
{
data << url.getPostData();
// if the user-supplied headers didn't contain a content-type, add one now..
if (! headers.containsIgnoreCase ("Content-Type"))
headers << "Content-Type: application/x-www-form-urlencoded\r\n";
headers << "Content-length: " << (int) data.getDataSize() << "\r\n";
}
}
..but I don't have a server target that I could actually test that with, so would be good to know if it works for you!