【问题标题】:How to enable POST method on heroku server (for React app)? I am getting 405 method not allowed如何在 heroku 服务器上启用 POST 方法(用于 React 应用程序)?我得到 405 方法不允许
【发布时间】:2018-11-30 22:18:29
【问题描述】:

我得到了不允许的 405 方法。我正在使用 axios.post 进行登录。 该表单正在输入用户名和密码并发布以进行身份​​验证。 但是在控制台中的 heroku 错误中不允许使用 POST 方法。

请帮我告诉我如何在 heroku 上启用 POST 方法。或任何解决方案。

提前感谢enter image description here

【问题讨论】:

  • Cors 问题,你用的是什么后端类型?

标签: node.js reactjs axios


【解决方案1】:

这是一个 axios 帖子示例:

axios.post("test/test", {userName:'..', password:'..'}).then((result) => onSuccess(result.data), (error) => onError(error));

如果您在 Java 中使用 spring-boot,您可能会遇到 CORS 问题。尝试放入您的端点:

@CrossOrigin(origins = {"http://localhost:3000", "url2", "url3})

如果需要,请将“http://localhost:3000”替换为您的 localhost 网址。这是一个例子:

@CrossOrigin(origins = {"http://localhost:3000", "url2", "url3})
@RequestMapping(value = "/test", method = RequestMethod.POST)
ResponseEntity<HttpStatus> testLoginUser(@RequestBody DTO testDto) throws TestException {

     //Do Something..
}

我不知道服务器是如何实现的,所以:检查您是否有 CrossOrigin 问题或您的端点是否有安全问题。

【讨论】:

猜你喜欢
  • 2014-06-27
  • 2016-02-15
  • 2014-04-18
  • 1970-01-01
  • 2021-11-24
  • 1970-01-01
  • 2014-05-23
  • 1970-01-01
  • 2023-03-05
相关资源
最近更新 更多