reactjs – 使用反应禁止标头访问vuforia vws
发布时间:2020-12-15 05:07:12 所属栏目:百科 来源:网络整理
导读:我正在尝试使用react axios调用vuforia的webservice,读取 docs of vuforia并在我拨打电话时遵循这些步骤我在chrome的控制台日志中遇到错误,这是: xhr.js:121 Refused to set unsafe header "Date" 但如果我理解正确,我必须在请求中声明标题“Date”.我该如
我正在尝试使用react axios调用vuforia的webservice,读取
docs of vuforia并在我拨打电话时遵循这些步骤我在chrome的控制台日志中遇到错误,这是:
xhr.js:121 Refused to set unsafe header "Date" 但如果我理解正确,我必须在请求中声明标题“Date”.我该如何解决,这是我的代码: class App extends Component { componentDidMount() { var md5 = require('md5'); var base64 = require('base-64'); var hmacsha1 = require('hmacsha1'); var contentType = "application/json"; var hexDigest = "d41d8cd98f00b204e9800998ecf8427e"; var accessKey = "xxxxxxxxxxxx"; var secretKey = "xxxxxxxxxxx"; var date = new Date().toUTCString(); var url = `${'https://cors-anywhere.herokuapp.com/'}https://vws.vuforia.com/targets`; var dateValue = date; var requestPath = url; var newLine = 'n'; var toDigest = `GET${newLine}${hexDigest}${newLine}${contentType}${newLine}${dateValue}${newLine}${requestPath}`; var shaHashed = hmacsha1(secretKey,toDigest); var signature = base64.encode(shaHashed); const config = { headers: { 'Date': `${date}`,'Authorization': `VWS ${accessKey}:${signature}` } } console.log(toDigest); axios.get(url,config,{ crossdomain: true }) .then(json => console.log(json)) } 的console.log(toDigest): GET d41d8cd98f00b204e9800998ecf8427e application/json Mon,29 Oct 2018 12:45:26 GMT https://cors-anywhere.herokuapp.com/https://vws.vuforia.com/targets
从中更改配置代码
const config = { headers: { 'Date': `${date}`,'Authorization': `VWS ${accessKey}:${signature}` } 至 const config = { headers: { 'Authorization': `VWS ${accessKey}:${signature}` } XMLHttpRequest不允许设置Date标头,它由浏览器自动设置.原因是通过操纵这些头文件,您可能会欺骗服务器通过相同的连接接受第二个请求,这个连接不会通过通常的安全检查 – 这将是浏览器中的安全漏洞.这是the list of HTTP headers你不能自己设定. 如果您仍然收到错误,请告诉我. (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |