【问题标题】:How can I remove "net::ERR_NAME_NOT_RESOLVED"?如何删除“net::ERR_NAME_NOT_RESOLVED”?
【发布时间】:2021-06-21 23:49:06
【问题描述】:
import Axios from 'axios';
import './App.css';  

function App() {

  const [userNameReg, setUserNameReg] = useState('')
  const [passwordReg, setPasswordReg] = useState('')

  const register = () =>{
    Axios.post("http://localhost3001/register", {
      username : userNameReg,
      password : passwordReg,
    }).then((res) =>{
      console.log(res);
    });
  };
  1. POST http://localhost3001/register net::ERR_NAME_NOT_RESOLVED
  2. 未捕获(承诺)错误:网络错误
  • 在 createError (createError.js:16) 时
  • 在 XMLHttpRequest.handleError (xhr.js:84) 处

【问题讨论】:

    标签: javascript html node.js reactjs express


    【解决方案1】:

    看来你在 url 中缺少 ':'

    axios.post("http://localhost3001/register", {

    应该是

    axios.post("http://localhost:3001/register", {

    【讨论】:

      【解决方案2】:

      该网址的格式似乎不正确。这应该有效:

      import Axios from 'axios';
      import './App.css';  
      
      function App() {
      
        const [userNameReg, setUserNameReg] = useState('')
        const [passwordReg, setPasswordReg] = useState('')
      
        const register = () =>{
          Axios.post("http://localhost:3001/register", {
            username : userNameReg,
            password : passwordReg,
          }).then((res) =>{
            console.log(res);
          });
        };
      };
      

      【讨论】:

      • 谢谢。它工作正常。但数据不会进入数据库。
      • 谢谢。它工作正常。但数据不会进入数据库。
      • 如果您成功获得 API 响应,那么这就是您需要查看后端的内容。 @ThanukshiWickramasinghe
      猜你喜欢
      • 2015-10-06
      • 2016-02-07
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 2018-04-28
      • 1970-01-01
      • 2021-06-05
      • 1970-01-01
      相关资源
      最近更新 更多