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
最满意答案
对于材质图表,需要设置选项 - >
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 ...
-
Google地理图表不会在Angular Material mdTabs中呈现(Google Geo Chart does not render inside Angular Material mdTabs)[2022-06-23]
使用该指令并确保最初加载图表, 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 ...