小编las*_*han的帖子

使用“Content-Type”从 axios 发送 post 请求:“application/x-www-form-urlencoded”给出 401 Unauthorized 响应

我正在向POST服务器发送请求,以通过 axios 获取Content-Type标头为x-www-form-urlencoded. 我用邮递员试过同样的方法,效果很好。我在请求正文中发送一个 grant_type 和 client_credentials 的键值对。

这是我的 axios 请求:

axios.post(`${baseURI}/protocol/openid-connect/token`, data, {
  headers : {
    "Authorization" : "Basic " + token,
    "Content-Type" : "application/x-www-form-urlencoded"
  },
  withCredentials: true
}).then(response => {
  AUTH_TOKEN = response.data.access_token;
  console.log(response.data);
}).catch(error => {
  console.log(error.response);
})
Run Code Online (Sandbox Code Playgroud)

数据对象由 client_credentials 组成。相同的凭据在邮递员中给出了成功的响应。

node.js axios

6
推荐指数
1
解决办法
6416
查看次数

标签 统计

axios ×1

node.js ×1