首页 \ 问答 \ Http状态415即使提供正确的ContentType(Http Status 415 even when providing correct ContentType)

Http状态415即使提供正确的ContentType(Http Status 415 even when providing correct ContentType)

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

HTTP状态415 - 执行POST时不支持的媒体类型

使用Alamofire分段上传时的HTTP状态415

尝试访问localhost时出现HTTP错误500

请求因HTTP状态415而失败

根据Autodesk的文档,我的请求结构完全正常,但似乎抛出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);

I'm attempting to set up a quick POC of an Autodesk Viewing App but I'm running into issues with authentication. I've already checked the following questions for general help but they're either covering extremely specific issues like HashTableMapping or haven't even been answered:

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

According to Autodesk's documentation my request structure is totally fine but seems to be throwing a 415 error. Anyone have any ideas or see something I'm not seeing? Here's my code below:

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

原文:https://stackoverflow.com/questions/37908251
更新时间:2022-07-28 09:07

最满意答案

对于材质图表,需要设置选项 - > backgroundColor.fill

和/或 - > chartArea.backgroundColor

backgroundColor: {
  fill: 'magenta'
},
chartArea: {
  backgroundColor: 'cyan'
},

也不能忘记转换选项...

google.charts.Line.convertOptions(materialOptions)


请参阅以下工作片段...

google.charts.load('current', {
  callback: drawChart,
  packages: ['line', 'corechart']
});

function drawChart() {
  var chartDiv = document.getElementById('chart_div');

  var data = new google.visualization.DataTable();
  data.addColumn('date', 'Month', 'Day', 'Hour','Min' );
  data.addColumn('number', "Battery Level");
  data.addColumn('number', "Solar Output");

  data.addRows([
    [new Date(2014, 1, 1, 8, 10),  -.5,  5.7],
    [new Date(2014, 1, 1, 8, 20),   .4,  8.7],
    [new Date(2014, 1, 1, 8 ,40),   .5,   12],
    [new Date(2014, 1, 1, 8 ,45),  2.9, 15.3],
    [new Date(2014, 1, 1, 8 ,60),  6.3, 18.6],
    [new Date(2014, 1, 1, 9 ,5),  9, 20.9],
    [new Date(2014, 1, 1, 9 ,12) , 10.6, 19.8],
    [new Date(2014, 1, 1, 9 ,18) , 10.3, 16.6],
    [new Date(2014, 1, 1, 9 ,28),  7.4, 13.3],
    [new Date(2014, 1, 1, 9 ,38),  4.4,  9.9],
    [new Date(2014, 1, 1, 9 ,48), 1.1,  6.6],
    [new Date(2014, 1, 1, 9 ,58), -.2,  4.5]
  ]);


  var materialOptions = {
    height: 300,
    chart: {
      title: 'Solar and Battery Overview',
    },
    backgroundColor: {
      fill: 'magenta'
    },
    chartArea: {
      backgroundColor: 'cyan'
    },
    series: {
      // Gives each series an axis name that matches the Y-axis below.
      0: {axis: 'Temps'},
      1: {axis: 'Daylight'}
    },
    axes: {
      // Adds labels to each axis; they don't have to match the axis names.
      y: {
        Temps: {label: 'Battery Level'},
        Daylight: {label: 'Solar Output'}
      }
    }

  };

  function drawMaterialChart() {
    var materialChart = new google.charts.Line(chartDiv);
    materialChart.draw(data, google.charts.Line.convertOptions(materialOptions));
  }

  drawMaterialChart();
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>


for material charts, need to set option --> backgroundColor.fill

and / or --> chartArea.backgroundColor

backgroundColor: {
  fill: 'magenta'
},
chartArea: {
  backgroundColor: 'cyan'
},

also mustn't forget to convert the options...

google.charts.Line.convertOptions(materialOptions)


see following working snippet...

google.charts.load('current', {
  callback: drawChart,
  packages: ['line', 'corechart']
});

function drawChart() {
  var chartDiv = document.getElementById('chart_div');

  var data = new google.visualization.DataTable();
  data.addColumn('date', 'Month', 'Day', 'Hour','Min' );
  data.addColumn('number', "Battery Level");
  data.addColumn('number', "Solar Output");

  data.addRows([
    [new Date(2014, 1, 1, 8, 10),  -.5,  5.7],
    [new Date(2014, 1, 1, 8, 20),   .4,  8.7],
    [new Date(2014, 1, 1, 8 ,40),   .5,   12],
    [new Date(2014, 1, 1, 8 ,45),  2.9, 15.3],
    [new Date(2014, 1, 1, 8 ,60),  6.3, 18.6],
    [new Date(2014, 1, 1, 9 ,5),  9, 20.9],
    [new Date(2014, 1, 1, 9 ,12) , 10.6, 19.8],
    [new Date(2014, 1, 1, 9 ,18) , 10.3, 16.6],
    [new Date(2014, 1, 1, 9 ,28),  7.4, 13.3],
    [new Date(2014, 1, 1, 9 ,38),  4.4,  9.9],
    [new Date(2014, 1, 1, 9 ,48), 1.1,  6.6],
    [new Date(2014, 1, 1, 9 ,58), -.2,  4.5]
  ]);


  var materialOptions = {
    height: 300,
    chart: {
      title: 'Solar and Battery Overview',
    },
    backgroundColor: {
      fill: 'magenta'
    },
    chartArea: {
      backgroundColor: 'cyan'
    },
    series: {
      // Gives each series an axis name that matches the Y-axis below.
      0: {axis: 'Temps'},
      1: {axis: 'Daylight'}
    },
    axes: {
      // Adds labels to each axis; they don't have to match the axis names.
      y: {
        Temps: {label: 'Battery Level'},
        Daylight: {label: 'Solar Output'}
      }
    }

  };

  function drawMaterialChart() {
    var materialChart = new google.charts.Line(chartDiv);
    materialChart.draw(data, google.charts.Line.convertOptions(materialOptions));
  }

  drawMaterialChart();
}
<script type="text/javascript" src="https://www.gstatic.com/charts/loader.js"></script>
<div id="chart_div"></div>

相关问答

更多
  • 在此Google Groups讨论区中,默认的颜色数组没有记录,因此无法访问。 但是,如果你想要一系列的颜色, Xavier Gumara就会发布它,就像asgallant一样 : {"#3366cc","#dc3912","#ff9900","#109618","#990099","#0099c6","#dd4477","#66aa00","#b82e2e","#316395","#994499","#22aa99","#aaaa11","#6633cc","#e67300","#8b0707","#65 ...
  • 这显然是谷歌图表API的一个错误,但我只想找到一个解决方法。 对于那些可能遇到相同问题的人,只需重复两次,即可将单点加倍: 在URL更改: chd = t:50 | 5(生成单点但在(0,5)位置 - 错误) 至: chd = t:50,50 | 5,5(生成单点正确放置(50,5) 这是完整的网址: http://chart.apis.google.com/chart?chxl=0:|0|X|100|1:|0|Y|5.0&chxt=x,y&chs=560x240&cht=lxy&chco=5EB3FFFD ...
  • 对于材质图表,需要设置选项 - > backgroundColor.fill 和/或 - > chartArea.backgroundColor backgroundColor: { fill: 'magenta' }, chartArea: { backgroundColor: 'cyan' }, 也不能忘记转换选项... google.charts.Line.convertOptions(materialOptions) 请参阅以下工作片段... google.charts.load('cur ...
  • 经过2天的R&DI得到了解决方案 google.charts.load('current', {'packages':['line']}); go ...
  • 使用该指令并确保最初加载图表, var app = angular.module('app', ['ngMaterial', 'googlechart']); app.controller('ChartController', function($scope) { var chart1 = {}; chart1.type = "GeoChart"; chart1.data = [ ['Locale', 'Count', 'Percent'], ...
  • 材料图表上的选项根本不可用... 请参阅 - > 物料图表特征奇偶校验的跟踪问题#2143 当使用核心图表时,有一个选项可以使图表“接近” 物料图表... theme: 'material' 请参阅以下工作代码段... google.charts.load('current', { callback: drawChart, packages: ['corechart'] }); function drawChart() { var data = new google.visual ...

相关文章

更多

最新问答

更多
  • 您如何使用git diff文件,并将其应用于同一存储库的副本的本地分支?(How do you take a git diff file, and apply it to a local branch that is a copy of the same repository?)
  • 将长浮点值剪切为2个小数点并复制到字符数组(Cut Long Float Value to 2 decimal points and copy to Character Array)
  • OctoberCMS侧边栏不呈现(OctoberCMS Sidebar not rendering)
  • 页面加载后对象是否有资格进行垃圾回收?(Are objects eligible for garbage collection after the page loads?)
  • codeigniter中的语言不能按预期工作(language in codeigniter doesn' t work as expected)
  • 在计算机拍照在哪里进入
  • 使用cin.get()从c ++中的输入流中丢弃不需要的字符(Using cin.get() to discard unwanted characters from the input stream in c++)
  • No for循环将在for循环中运行。(No for loop will run inside for loop. Testing for primes)
  • 单页应用程序:页面重新加载(Single Page Application: page reload)
  • 在循环中选择具有相似模式的列名称(Selecting Column Name With Similar Pattern in a Loop)
  • System.StackOverflow错误(System.StackOverflow error)
  • KnockoutJS未在嵌套模板上应用beforeRemove和afterAdd(KnockoutJS not applying beforeRemove and afterAdd on nested templates)
  • 散列包括方法和/或嵌套属性(Hash include methods and/or nested attributes)
  • android - 如何避免使用Samsung RFS文件系统延迟/冻结?(android - how to avoid lag/freezes with Samsung RFS filesystem?)
  • TensorFlow:基于索引列表创建新张量(TensorFlow: Create a new tensor based on list of indices)
  • 企业安全培训的各项内容
  • 错误:RPC失败;(error: RPC failed; curl transfer closed with outstanding read data remaining)
  • C#类名中允许哪些字符?(What characters are allowed in C# class name?)
  • NumPy:将int64值存储在np.array中并使用dtype float64并将其转换回整数是否安全?(NumPy: Is it safe to store an int64 value in an np.array with dtype float64 and later convert it back to integer?)
  • 注销后如何隐藏导航portlet?(How to hide navigation portlet after logout?)
  • 将多个行和可变行移动到列(moving multiple and variable rows to columns)
  • 提交表单时忽略基础href,而不使用Javascript(ignore base href when submitting form, without using Javascript)
  • 对setOnInfoWindowClickListener的意图(Intent on setOnInfoWindowClickListener)
  • Angular $资源不会改变方法(Angular $resource doesn't change method)
  • 在Angular 5中不是一个函数(is not a function in Angular 5)
  • 如何配置Composite C1以将.m和桌面作为同一站点提供服务(How to configure Composite C1 to serve .m and desktop as the same site)
  • 不适用:悬停在悬停时:在元素之前[复制](Don't apply :hover when hovering on :before element [duplicate])
  • 常见的python rpc和cli接口(Common python rpc and cli interface)
  • Mysql DB单个字段匹配多个其他字段(Mysql DB single field matching to multiple other fields)
  • 产品页面上的Magento Up出售对齐问题(Magento Up sell alignment issue on the products page)