问题描述
feign调用get请求报405错误
原因分析:
FeignClient最后是用HttpURLConnectiion发起的网络连接,在发起的过程中,Connection会判断其自身的body是否为空,如果不为空,则将 GET Method 转换为 POST Method。并且参数默认放到请求体,所以建议服务调用接口使用post请求。若使用get请求,需要添加@RequestParam注解。
@FeignClient(value = "usercenter" ,path = "/rest",url = "${}")
public interface IFeignWlwUserCenterService {
/**
* 获取当前用户
* @param token 认证信息
*/
@GetMapping("/core/auth/user")
ResWlwUserCurrentUser getCurrentuser(@RequestParam("token") String token);
}
文章讨论了FeignClient中GET请求被自动转换为POST的问题,因为Feign使用HttpURLConnection时,若GET方法带有非空body,会被转为POST。为避免405错误,建议使用POST请求或对GET接口参数使用@RequestParam注解。

3945

被折叠的 条评论
为什么被折叠?



