我试图向 apiary API 发送请求,但标头始终无效。API 期望字符集为 'utf-8',在代码中正确设置。在api网站的inspector处可以看到请求已经将charset设置为UTF-8... 为什么请求中的charset是大写的?我该如何解决?
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));