我不知道为什么连接已关闭

I couldn't figure out why is the conncection is closed

我正在将数据发布到 wordpress api 但我遇到了关闭连接的问题.. 第一次它工作但我不知道发生了什么

handleSignIn = () => {
        const post = {
            "email" : this.state.email,
            "password " : this.password
        }
        axios.post('http://api.piri.ai:3000/v1/public/login' , post)
            .then(res => {this.setState({status: res.data.status})  
            //window.location= '/wp';
            console.log(res.data)
        })
            .catch(e => {console.log(e.message) ; this.setState({status: false})});


    }

在控制台日志中,我收到此错误

网络错误 xhr.js:166 个选项 https://api.piri.ai:3000/v1/public/login net::ERR_CONNECTION_CLOSED

更新答案

我已经用 postman 测试了你的 API,它在 postman 中运行良好。见下图。

也将它集成到 React 应用程序中。但实际问题是 CORS。因此,您的服务器应该启用跨源请求。

旧答案

能否在header

中添加以下代码
 headers:{
     'Content-Type': 'application/x-www-form-urlencoded',
     'Accept': 'application/json'
}

您可以像下面这样在 catch 部分处理网络错误。

catch(error => {
  if (!error.response) {
      // network error
      this.errorStatus = 'Error: Network Error';
  } else {
      this.errorStatus = error.response.data.message;
  }
})