【问题标题】:Http Status 415 even when providing correct ContentTypeHttp Status 415 即使提供正确的 ContentType
【发布时间】:2016-10-20 20:48:08
【问题描述】:

我正在尝试设置 Autodesk 查看应用程序的快速 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);

【问题讨论】:

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


    【解决方案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);
    

    【讨论】:

    • 很高兴你设法修复它...记得“接受解决方案”:-)
    猜你喜欢
    • 2019-06-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2020-09-16
    • 2018-09-24
    • 2021-05-14
    • 2016-10-25
    • 2020-07-16
    相关资源
    最近更新 更多