养蜂场无效 Header

Apiary Invalid Header

我正在尝试向 api 库 API 发送请求,但 header 始终无效。 API 期望字符集为 'utf-8',它已在代码中正确设置。在 api 网站的检查器中,您可以看到请求已将字符集设置为 UTF-8... 为什么请求中的字符集是 capital 个字母?我该如何解决?

var Request = new XMLHttpRequest();
Request.open('POST', 'URL');
Request.setRequestHeader('Content-Type', 'application/json; charset=utf-8'); //utf-8!!!
Request.onreadystatechange = function () {
  if (this.readyState === 4) {
    console.log('Status:', this.status);
    console.log('Headers:', this.getAllResponseHeaders());
    console.log('Body:', this.responseText);
  }
};

var body = {
  //JSON stuff
};

Request.send(JSON.stringify(body));

看起来 XMLHttpRequest 在发送请求时将字符集更改为大写 UTF-8。通过 Apiary.io 文档尝试请求时,它将内容类型的字符集保持为小写 utf-8 并表示请求有效。当我 copy/paste 代码示例进入 Chrome 的控制台并查看发出的请求时,它更改了字符集大写,这表明这是一个无效请求。

在关于设置字符集的 jQuery 文档中,它是这样说的:

The W3C XMLHttpRequest specification dictates that the charset is always UTF-8; specifying another charset will not force the browser to change the encoding.

鉴于此,我尝试将字符集更改为其他字符集,但它仍然在请求中显示为 charset=UTF-8,所以我最初的想法是它总是大写的。