Request method ‘GET‘ not supported,不支持GET形式访问

简介: Request method ‘GET‘ not supported,不支持GET形式访问

org.springframework.web.HttpRequestMethodNotSupportedException: Request method ‘GET’ not supported


原因:异常提示的很明确,请求不支持GET方式访问,出现这种问题一般都是由于限制请求接口为POST,然后使用GET形式访问造成的。


解决方案:碰到这种问题有的小伙伴可能很懵逼,除萌新外大部分人都了解,既然限制了接口的访问类型,那肯定会用自己设定的访问类型去访问,比如你一个POST接口肯定不会用GET形式方式,但是有时候明明用POST形式访问了却仍然给你出来这个异常,这种问题一般都是由调用的jar包重定向后引起的。


比如你的接口设定时这样形式的


然后你调用的方法是这样的


然而他还是给你报了一个Request method ‘GET’ not supported异常

到这里就懵逼了,POST接口POST形式调用没毛病啊。


但是你可能会配置这样一个东西


这里有一个过滤器,配置了所有接口在访问时都需要经过认证,并且配置未认证时的重定向页面,我们将它委托给ShiroFilterFactoryBean自动管理,这个时候如果你去访问/userLogin这个接口的话是未认证状态的,所以他会将其重定向的/login接口,然而如果你将这个接口设置为/userLogin时,

ShiroFilterFactoryBean就会将其重定向到/userLogin接口(重定向是Get形式),而/userLogin又是只限制POST形式才能访问的,所以就出现了上述异常。


建议将上图1位置的接口换成一个初始化页面的接口,这样就不会造成Request method ‘GET’ not supported异常了,如下图所示。



补充:返回到index页面后你可能会发现自己的静态资源无法访问了,这个时候你就需要在过滤器中配置某些不需要认证,直接能够访问的资源了


目录
相关文章
|
6月前
|
前端开发 应用服务中间件
SpringMVC 文件上传 消息 Required request part ‘file‘ is not present描述 由于被认为是客户端对错误(例如:畸形的请求语法、无效的请求信息帧或者
SpringMVC 文件上传 消息 Required request part ‘file‘ is not present描述 由于被认为是客户端对错误(例如:畸形的请求语法、无效的请求信息帧或者
416 0
|
XML JSON Java
权威分析@RequestParam和@RequestPart 的区别(官方文档)
一、今天写了两个文件上传的接口用到了@RequestParam和@RequestPart @RequestPart /** * 单文件上传 * @param file * @par...
9553 0
|
JSON 移动开发 应用服务中间件
调用Feign接口报错:JSON parse error:Illegal character ((CTRL-CHAR, code 31))
调用Feign接口报错:JSON parse error:Illegal character ((CTRL-CHAR, code 31))
2986 0
调用Feign接口报错:JSON parse error:Illegal character ((CTRL-CHAR, code 31))
|
4天前
|
应用服务中间件 Apache
消息 Request method ‘POST‘ not supported
消息 Request method ‘POST‘ not supported
Kam
|
Java Maven
Feign调用把GET请求自动转成POST请求解决:Request method 'POST' not supported
Feign调用把GET请求自动转成POST请求解决:Request method 'POST' not supported
Kam
1632 0
|
7月前
|
Java
【Java异常】Feign常见的坑总结之一:Method Not Allowed“,“message“:“Request method ‘POST‘ not supported“,“path“:“/*
【Java异常】Feign常见的坑总结之一:Method Not Allowed“,“message“:“Request method ‘POST‘ not supported“,“path“:“/*
108 0
|
SQL 关系型数据库 MySQL
【解决思路】HTTP Status 500 Type Exception ReportMessage Request processing failed; 【已解决】
经常测试的一个网页,突然报错500。前面也没有发生过,但突然报错,只能先改错了,不然都没法进入页面。为什么会调用到存在bug的语句,而以前没有发生这种情况?这一问题没能想清楚,只能归咎于编译器了。
303 0
【解决思路】HTTP Status 500 Type Exception ReportMessage Request processing failed; 【已解决】
|
Java Spring
springmvc:405 request method post not supported
springmvc:405 request method post not supported
133 0
Method search not annotated with HTTP method type (ex. GET, POST)
Method search not annotated with HTTP method type (ex. GET, POST)
782 0