Box API调用在Vue中返回403禁止的错误,但在邮递员中使用相同的URL

时间:2019-04-03 06:26:16

标签: vue.js xmlhttprequest axios postman box-api

我为box创建了开发者令牌,并且box应用都已设置好。当我使用邮递员时,我会得到返回的数据。我查看了Postman发送的标头,并在我的代码中提供了相同的标头。

axios({
    async: true,
    crossDomain: true,
    url: 'https://api.box.com/2.0/files/<File ID>/',
    method: 'GET',
    headers: {
      'Postman-Token': '<Postman Token>',
      'cache-control': 'no-cache',
      Authorization: 'Bearer <Developer Token>',
      Accept: '*/*',
    },
  }).then((res) => {
    console.log(res);
  }).catch(console.error);

这将在浏览器中返回403。

这是邮递员的回复标题:

Date:"Wed, 03 Apr 2019 06:04:45 GMT"
Content-Type:"application/json"
Transfer-Encoding:"chunked"
Connection:"keep-alive"
Strict-Transport-Security:"max-age=31536000"
Cache-Control:"no-cache, no-store"
ETag:""0""
Content-Encoding:"gzip"
Vary:"Accept-Encoding"
BOX-REQUEST-ID:"<BOX-REQUEST-ID>"
Age:"0"

bowser的响应标头

Access-Control-Allow-Origin: *
Age: 0
BOX-REQUEST-ID: <BOX-REQUEST-ID>
Cache-Control: no-cache, no-store
Connection: keep-alive
Content-Encoding: gzip
Content-Type: application/json
Date: Wed, 03 Apr 2019 06:36:01 GMT
Strict-Transport-Security: max-age=31536000
Transfer-Encoding: chunked
Vary: Origin,Accept-Encoding

浏览器开发工具中的错误

GET https://api.box.com/2.0/files/<File ID>/ 403 (Forbidden)
Error: Request failed with status code 403
    at createError (createError.js?2d83:16)
    at settle (settle.js?467f:18)
    at XMLHttpRequest.handleLoad (xhr.js?b50d:77)

0 个答案:

没有答案