Axios Call返回错误401 - 刷新一切后很好

时间:2017-12-21 02:02:34

标签: odata axios

我正在做一个axios电话。

我的代码:

loginSAP () {
  var config = {
    url: 'http://linkToSAPoDataService/oDataSet?&format=json',
    withCredentials: true
  }
  this.axios(config)
}

首先需要先登录才能访问我的数据库。

登录后,我得到:

Failed to load resource: the server responded with a status of 401 (Unauthorized)
createError.js:15 Uncaught (in promise) Error: Request failed with status code 401
    at createError (createError.js:15)
    at settle (settle.js:18)
    at XMLHttpRequest.handleLoad (xhr.js:77)

我无法立即访问数据 - 当我刷新页面时,一切都很好并且正常工作。

我必须在刷新之前访问并显示数据

您对我的电话有什么不妥吗?

1 个答案:

答案 0 :(得分:0)

似乎您的axios配置在登录后不会更新。您可以使用拦截器将登录令牌(例如)添加到axios配置中。

Windows cannot open the folder.

The Compressed (zipped) Folder 'C:\Users\me\Downloads\test.zip' is invalid.

因此,登录后,所有请求都具有有效令牌,无需刷新页面即可重置配置。