Return to site

405 Post Not Supported

broken image


2HTTP Status 405 - Request method 'POST' not supported (Spring MVC) 3jsp spring mvc 上传时HTTP Status 405 - Request method 'GET' not supported是什么原因; 4置顶 Spring-boot、Spring-jdbc 、Spring-mvc; 5Java web高级编程——Spring MVC; 6Spring boot MVC: can't find JSP. Despite the rather easy workaround, such an issue is definitely a though one, as it will easily affect most ASP.NET Core Web API and Web Applications when they get deployed on a live environment: that's because the WebDAV module, although not supported by IIS Express, happens to be enabled in most production servers.

2020腾讯云限时秒杀,爆款1核2G云服务器99元/年!(领取2860元代金券),
地址:https://cloud.tencent.com/act/cps/redirect?redirect=1062

Supported

2020阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods

推荐:HTTP Status 405 - Request method 'POST' not supported (Spring MVC)

HTTP Status 405 - Request method 'POST' not supported (Spring MVC) javaspringspring-mvcspring-boot
|
this questionedited Jul 13 '14 at 6:11 asked Jul 13 '14 at 5:28 user3833530 30 1 1 4

|

6 Answers
6

解决方法

Have a look at the logs (with security at DEBUG) and you will discover the problem. Most likely you haven't disabled csrf protection and you client isn't sending the csrf token. (Standard Spring Security, not Spring Boot, although if you are using the Boot security autoconfig you can switch off csrf with an external config setting.)

Supported

|
this answer answered Jul 13 '14 at 6:25 Dave Syer 31.1k 5 82 91 The config setting for Spring Boot: security.enable-csrf=false – naXa Feb 28 '16 at 23:25 |

I had same error because of csrf protection. If csrf protection is enabled you need to send csrf parameters in request header.

You can also check Spring documentation here.

I added this parameters into my jsp file

And modified my ajax call like below.


|
this answeredited Apr 18 '15 at 8:01Timeless 1,907 5 29 56 answered Nov 17 '14 at 0:03 fyelci 452 7 15 O'Man! you saved my day! this really works. +1 for great effort. – Arshad Ali May 10 '16 at 12:42 |

First of all, in Spring 4 you can use @RestController annotation on your rest controller class, which allows you to remove @RequestBody annotations from your methods. Makes it cleaner.

For second, would you maybe show more of your angular code? I think you should consider using factory services to make requests to backend. For example, have a service (this service already provides post, get, delete by default):

Now in your Angular controller you make a new User object that you use to call this service methods.

推荐:Spring Boot 之 MVC

上一次我们使用Spring Boot开发了一个简单的REST服务应用,那么传统网页应用怎么做呢? 渲染HTML是Spring Boot可以完美胜任的,并且提供了多种模板引擎的默认配

Not

Query all (GET): User.query();

Query one (GET): User.get({id: userId});

Insert (POST): User.$save();

Update (PUT): User.$update();

Remove (DELETE): User.delete({id: userId}

I've written my Angular apps like that also using Spring boot and works well.


|
this answeredited Jul 13 '14 at 11:34 answered Jul 13 '14 at 11:25 Vaelyr 1,148 1 4 15 I use jspViewResolver to direct to specific jsp pages. Once I change my to @RestController it no longer works do I have to create another Class that uses @Controller to direct to specific jsp pages? – Eric Huang Dec 12 '16 at 4:31 You cannot use both of them together. You either 1) return JSON and use it in front-end 2) put your data into model map and return view. – Vaelyr Dec 12 '16 at 10:56 |

I had the same problem and resolved it by using the @RestController annotation instead of the 'plain' @Controller annotation on my controller.

405 Post Not Supported Resolution


|
Error 405 post method not supported
this answer answered Apr 21 '15 at 20:27 user3574606 11 1 This is the only solution that worked for me. Does anyone have any idea why? I was using Spring Boot with security starter and wanted to upload a multipart to

Spring 405 Post Not Supported

@Controller. After changing it to
405 Post Not Supported

2020阿里云最低价产品入口+领取代金券(老用户3折起),
入口地址:https://www.aliyun.com/minisite/goods

推荐:HTTP Status 405 - Request method 'POST' not supported (Spring MVC)

HTTP Status 405 - Request method 'POST' not supported (Spring MVC) javaspringspring-mvcspring-boot
|
this questionedited Jul 13 '14 at 6:11 asked Jul 13 '14 at 5:28 user3833530 30 1 1 4

|

6 Answers
6

解决方法

Have a look at the logs (with security at DEBUG) and you will discover the problem. Most likely you haven't disabled csrf protection and you client isn't sending the csrf token. (Standard Spring Security, not Spring Boot, although if you are using the Boot security autoconfig you can switch off csrf with an external config setting.)


|
this answer answered Jul 13 '14 at 6:25 Dave Syer 31.1k 5 82 91 The config setting for Spring Boot: security.enable-csrf=false – naXa Feb 28 '16 at 23:25 |

I had same error because of csrf protection. If csrf protection is enabled you need to send csrf parameters in request header.

You can also check Spring documentation here.

I added this parameters into my jsp file

And modified my ajax call like below.


|
this answeredited Apr 18 '15 at 8:01Timeless 1,907 5 29 56 answered Nov 17 '14 at 0:03 fyelci 452 7 15 O'Man! you saved my day! this really works. +1 for great effort. – Arshad Ali May 10 '16 at 12:42 |

First of all, in Spring 4 you can use @RestController annotation on your rest controller class, which allows you to remove @RequestBody annotations from your methods. Makes it cleaner.

For second, would you maybe show more of your angular code? I think you should consider using factory services to make requests to backend. For example, have a service (this service already provides post, get, delete by default):

Now in your Angular controller you make a new User object that you use to call this service methods.

推荐:Spring Boot 之 MVC

上一次我们使用Spring Boot开发了一个简单的REST服务应用,那么传统网页应用怎么做呢? 渲染HTML是Spring Boot可以完美胜任的,并且提供了多种模板引擎的默认配

Query all (GET): User.query();

Query one (GET): User.get({id: userId});

Insert (POST): User.$save();

Update (PUT): User.$update();

Remove (DELETE): User.delete({id: userId}

I've written my Angular apps like that also using Spring boot and works well.


|
this answeredited Jul 13 '14 at 11:34 answered Jul 13 '14 at 11:25 Vaelyr 1,148 1 4 15 I use jspViewResolver to direct to specific jsp pages. Once I change my to @RestController it no longer works do I have to create another Class that uses @Controller to direct to specific jsp pages? – Eric Huang Dec 12 '16 at 4:31 You cannot use both of them together. You either 1) return JSON and use it in front-end 2) put your data into model map and return view. – Vaelyr Dec 12 '16 at 10:56 |

I had the same problem and resolved it by using the @RestController annotation instead of the 'plain' @Controller annotation on my controller.

405 Post Not Supported Resolution


|
this answer answered Apr 21 '15 at 20:27 user3574606 11 1 This is the only solution that worked for me. Does anyone have any idea why? I was using Spring Boot with security starter and wanted to upload a multipart to

Spring 405 Post Not Supported

@Controller. After changing it to @RestController it started working for some reason. I do not like not knowing why... Any ideas? – Cleankod Nov 24 '15 at 19:38 What is more interesting, the exception was thrown after the request has been successfully processed inside the controller method (at the exiting of the method). – Cleankod Nov 24 '15 at 19:45 |

Your problem is that the endpoints for findById and updateUser are the same which is api/users/{id} and since the one with GET method comes first it will be evaluated first when you send a PUT request and hence will be rejected by spring.

I suggest you change the endpoint for updating user to api/users/update/{id} as below:


|

Spring Boot 405 Request Method 'post' Not Supported


this answeredited Dec 12 '16 at 11:21 answered Dec 12 '16 at 11:15 Sohlowmawn 296 1 9 |

Your code on Spring MVC looks good to me, so I suspect the syntax on AngularJS being correct. I am not familiar with AngularJS, but I found an online tutorial regarding the $http function

from this link, http://tutorials.jenkov.com/angularjs/ajax.html

Hope it will help.


|
this answer answered Jul 13 '14 at 5:52 Dino Tw 1,230 1 15 29 thanks for the response, I'm much more familiar with the angular side than the spring side. The $http request is valid and produces the expected result (an HTTP PUT request to localhost/api/users/1). I've also manually hit this endpoint using the chrome extension Postman. I'm not terribly familiar with spring boots auto configuration and am thinking that maybe there is some kind of manual configuration that needs to happen to enable PUT and POST requests, but then again I don't really know if that is the case. – user3833530 Jul 13 '14 at 6:08 |

推荐:Spring MVC拦截405错误

Spring MVC框架对常见的全局异常都做了很好的处理,一般情况下我们无需关心和干预。默认情况下,如果出现如404、405等错误时,Spring会返回一个默认的ModelAndVi

405 Post Not Supported Device

  • 1Spring mvc+hibernate+freemarker(开源项目)
  • 2Spring mvc+hibernate+freemarker(开源项目) - java,oracle,mysql,jquery,linux,Struts,Spring,Hibernate,maven webservices,Nosql,hudoop,git,osgi,easymock,nginx,jbpm,jni,jpa等资料下载地址 http://pa
  • 1微信公众号文章采集,并发布到WordPress
  • 2HTTP Status 405 - Request method 'POST' not supported (Spring MVC)
  • 3Spring MVC拦截405错误
  • 4Spring Boot 之 MVC
  • 5jsp spring mvc 上传时HTTP Status 405 - Request method 'GET' not supported是什么原因
  • 6Customizing HttpMessageConverters with Spring Boot and Spring MVC

Error 405 Request Method 'post' Not Supported Postman

最新文章

405 Post Not Supported Ayatollah

  • 1在阿里架构师眼中构建一个较为通用的业务技术架构就是如此简单
  • 2Java基础类String了解一下
  • 3中国民航飞行学院人事薪资管理系统实践案例
  • 4Java SE——线程介绍
  • 5简单的方法构建一个高可用服务端
  • 6CTO详细讲解海量日志处理ELK




broken image