【问题标题】:Axios response showing status code 200 but no response dataaxios 响应显示状态码 200 但没有响应数据
【发布时间】:2019-09-07 07:52:03
【问题描述】:

我是 axios 的新手。我正在尝试发送带有授权标头的发布请求。响应数据在 Post man 中返回。但我在浏览器中看不到任何响应数据。请帮忙。

   axios.post('http://13.127.3.151:8080/v1/dashboard/getuserdetails', {
      utype: "staff",
      uemail: "abdulwahidnasir@bitsathy.ac.in"
    },
    { headers: { 'Authorization': `Bearer ${serviceToken}`,
                  'Content-Type': 'multipart/form-data' } })
    .then(response => {
      console.log(response);
    })
    .catch(error => {
      console.log(error.response)
  });

【问题讨论】:

  • 网络标签显示什么?
  • response.data 中的所有内容。 DATALIST 在 postman 中是 len 1 的数组,但在 axios 请求中是 len 0 的数组,但我认为这不是 axios 的问题。
  • 仅供参考。您也向世界公开了 Bearer 令牌。 确保更改它。当您不知道自己在做什么时,这是有风险的。
  • 网络选项卡在 DATALIST 中显示空响应
  • 不记名令牌每 3 分钟过期一次

标签: reactjs axios react-hooks


【解决方案1】:

我发现了问题,它与 formData 有关。现在可以正常使用了。

  let formData = new FormData();
  formData.append("utype", userType);
  formData.append("uemail", email);
  axios.post('http://13.127.3.151:8080/v1/dashboard/getuserdetails', formData,
    { headers: { 'Authorization': `Bearer ${serviceToken}`,
                  'Content-Type': 'multipart/form-data' } })
    .then(response => {
      console.log(response);
    })
    .catch(error => {
      console.log(error.response)
  });

【讨论】:

    猜你喜欢
    • 2020-12-20
    • 1970-01-01
    • 2015-09-30
    • 2022-01-22
    • 2021-11-16
    • 1970-01-01
    • 2023-02-20
    • 2017-08-08
    • 1970-01-01
    相关资源
    最近更新 更多