美文网首页IT@程序员猿媛程序员
Axios远程接口链接时,报404

Axios远程接口链接时,报404

作者: 嘀嘀Lemon | 来源:发表于2019-04-04 11:26 被阅读3次

前言

刚刚在项目中使用Axios远程调用后端接口时,出现以下异常:
Uncaught (in promise) Error: Request failed with status code 404

解决方法

将项目中的原Axios方法改造如以下代码所示:
改造前:

 axios.post({
          url: "这里是请求的的URL",
          timeout: 10000,
          //不带Cokkie
          withCredentials: false,
          headers: {
            "Content-Type": "application/x-www-form-urlencoded"
          },
          data: {
            "userName": this.username,
            "passWord": this.password
          }
        }).then((res) => {
          console.log(res);
          if (res.data.status == 0) {
            this.$Message.info("得到信息");
          } else {
            this.$Message.warning("未得到信息");
          }
        })

改造后:

var instance = axios.create({headers: {'content-type': 'application/x-www-form-urlencoded'}});
        instance.post(`这里是请求的的URL`, params).then((res) => {
          console.log(res);
        });

修改完后就可以成功链接了。

相关文章

网友评论

    本文标题:Axios远程接口链接时,报404

    本文链接:https://www.haomeiwen.com/subject/zilfiqtx.html