首页 > 解决方案 > Http调用Node.js问题,socket挂断错误

问题描述

我遇到了以下问题,所有通过 axios 的 HTTP 调用都可以正常工作,没有任何问题,几个小时后,所有调用都返回了以下错误:

socket hang up error

奇怪的是,来自 Postman 的相同调用没有问题,我想知道你们中是否有人遇到同样的问题以及如何解决它,这是我正在使用的代码:

const getToken = async (username, password) => {
  try {
    const body = {username, password}
    const url = `${API_URI.auth}`
    const options = {
      method: 'POST',
      url,
      headers: {
        'Content-Type': 'application/json'
      },
      data: JSON.stringify(body)
    }
    const response = await axios(options).then((res) => res.data.json())
    console.log(response)
    return response
  } catch (error) {
    console.log(error.message)
    return false
  }
}

标签: javascriptnode.jsexpresshttpaxios

解决方案


推荐阅读