How to remove Charset from Content-Type when using WinHTTP?

76 Views Asked by At

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

0

There are 0 best solutions below