When you use the WinHttpRequest object to POST data to a server:
IWinHttpRequest http = CoWinHttpRequest.Create();
http.Open("POST", "http://example.contoso.com/api/v1/grobber", false);
http.SetRequestHeader("Content-Type", "multipart/form-data;boundary=MultipartBoundary");
http.Send(formData);
the WinHTTP component will silenty change your Content-Type header; by appending Charset:
- Before:
Content-Type=multipart/form-data;boundary=MultipartBoundary - After:
Content-Type-multipart/form-data;boundary=MultipartBoundary;Charset=UTF-8
This runs afoul of a bug in Apache where it will not recognize any Content-Type header that contains Charset.
One suggestion online was to try to proactively add the Charset yourself, and add it earlier in the Content-Type string, so that maybe Apache will accept it:
http.SetRequestHeader("Content-Type", "Charset=UTF-8;multipart/form-data;boundary=MultipartBoundary");
except it doesn't work. It goes out to the server with Charset in the first position; but Apache still chokes on it.
How can I suppress WinHTTP from automatically adding a Charset to my Content-Type?
Bonus Reading
- MSDN Forums: How to remove "charset=UTF-8" from Content-Type
- MSDN Forums: Uploading File via HTTP Post from VBA does not work
- WinHttp.WinHttpRequest adding to the content-type
- MSDN Forums: How do I prevent WinHttpRequest from automatically appending Charset=UTF-8 to ContentType?
- Dart-lang: Remove charset from "Content-Type" header #184