Http状态415即使提供正确的ContentType

时间:2016-06-19 14:24:19

标签: xmlhttprequest autodesk-viewer autodesk-forge autodesk-model-derivative

我试图设置Autodesk Viewing App的快速POC,但我遇到了身份验证问题。我已经检查了以下问题以获得一般帮助,但他们要么涵盖HashTableMapping等非常具体的问题,要么甚至已经回答:

HTTP Status 415 - Unsupported Media Type when doing POST

HTTP status 415 when using Alamofire multipart upload

HTTP Error 500 when attempting to access localhost

The request failed with HTTP status 415

根据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);

1 个答案:

答案 0 :(得分:1)

得到它 - 是我自己错误的逻辑让我搞砸了。第一个请求标头格式不正确,我需要将我的信息作为值发送:

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);