即使提供正确的 ContentType,Http Status 415

Http Status 415 even when providing correct ContentType

我正在尝试设置 Autodesk 查看应用程序的快速 POC,但我 运行 遇到身份验证问题。我已经检查了以下问题以获得一般帮助,但它们要么涵盖了非常具体的问题,如 HashTableMapping,要么甚至没有得到回答:

根据 Autodesk 的 documentation,我的请求结构完全没问题,但似乎抛出 415 错误。任何人有任何想法或看到我没有看到的东西?下面是我的代码:

var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("references loaded");

var xhr = new XmlHttpRequest();
xhr.open("POST", "https://developer.api.autodesk.com/authentication/v1/authenticate", false);

var headerRequest = "Content-Type: application/x-www-form-urlencoded";
var headerValue = 
    "client_id=_someSecretValue_" + "&" +
    "client_secret=_someOtherSecretValue_" + "&" +
    "grant_type=client_credentials" + "&" +
    "scope=data:read";

xhr.setRequestHeader(headerRequest, headerValue);
xhr.send();

console.log(xhr.status); //getting a 415 here
console.log(xhr.statusText);

明白了 - 是我自己的错误逻辑把我搞砸了。第一个请求 header 格式不正确,我需要将我的信息作为值发送:

var XmlHttpRequest = require("xmlhttprequest").XMLHttpRequest;
console.log("references loaded");

var xhr = new XmlHttpRequest();
xhr.open("POST", "https://developer.api.autodesk.com/authentication/v1/authenticate", false);

//var headerRequest = "Content-Type:application/x-www-form-urlencoded";
var headerValue = 
    "client_id=_someSecretValue_" + "&" +
    "client_secret=_otherSecretValue_" + "&" +
    "grant_type=client_credentials" + "&" +
    "scope=data:read";

xhr.setRequestHeader("Content-Type", "application/x-www-form-urlencoded");
xhr.send(headerValue);

console.log(xhr.status);
console.log(xhr.statusText);