我的 url 在 Postman 中工作,但在浏览器中使用时不工作?

My url is working in Postman but Not working when using it from a browser?

我希望你做得很好,我有一个小问题,我正在使用 Symfony 4 开发一个 API,并在前端使用 ReactJs,所以我使用 axios 将我的数据发送到服务器, 这是它:

import Axios from "axios";

const sendLoginData = (username, password) => {
  Axios.post("localhost/api/login_check", { username, password }).then(
    response => {
      console.log(response);
    }
  );
};

export default sendLoginData;

数据发送正确,但似乎我的路由未知我在控制台中收到此错误:

xhr.js:166 POST http://localhost:3000/localhost/api/login_check 404 (Not Found)

但是当我在 Postman 上使用相同的 url 时,我得到了正确的令牌,这意味着我的身份验证没问题。

所以,我验证了一些答案并发现了一些与我相似的东西,一个在后端使用 .NET 的人遇到了同样的错误,但据我所知,数据是通过 url,但我相信我的情况不同。

我不知道如何解决这个问题,任何帮助将不胜感激。

如有任何帮助,我们将不胜感激。

在您的请求中添加方案。

在 postman 中你请求 http://localhost/api/login_check,但在 axios 中你请求 http://localhost/localhost/api/login_check

要解决这个问题:

Axios.post("http://localhost/api/login_check")