客户端使用 FeignClient 调用服务端服务时,报错:Request method ‘POST‘ not supported
客户端使用 FeignClient 调用服务端服务时,报错:Request method ‘POST‘ not supported
修改错误前调用方式:
FeignClient 接口服务
1 2 3 4 5 | @FeignClient (contextId = "remotePayFormService" , value = "payment-service-system" ) public interface RemotePayFormService { @GetMapping ( "/platPayForm/platPayFormList" ) R<PlatPayform> platPayFormList( @RquestBody PlatPayForm platPayForm @RequestHeader (SecurityConstants.FROM_SOURCE) String source); <br>} |
服务端代码代码
@RestController @RequestMapping("/platPayform") @Slf4j public class PlatePayMainController extends BaseController { @Autowired private IPlatPayFormService platPayFormService; /** * 支付集合 */ @InnerAuth @GetMapping("/platPayFormList") public R<PlatPayForm> platFormList(@RequestBody PlatPayForm platPayForm ) {
List<PlatFormName> list = platPayFormService.selectPlatPayFormList(null);
if (null != list)
return R.ok(list.get(0));
else
return null;
}
}
}
问题分析:【报错】 Resolved [org.springframework.web.HttpRequestMethodNotSupportedException: Request method 'POST' not supported]
提示:不支持Post请求,客户段使用 FeignClient 端用的是Get请求,服务端用的也为Get请求,为什么会报错不支持Post请求呢?
如吧客户端和服务端都改成Post请求后,就解决问题了。或使用get方式请求不用@RequestBody 注解 参数传递方式。
原因:
因为FeignClient 端的请求参数是 @RequestBody PlatPayForm platPayForm,当把对象转换为json字符串的时候 FeignClient会默认发送Post请求
解决方法
1、如果使用@RequestBody 注解,把客户端与服务端都改为Post请求
2、如果非要用Get传送对象类型参数,直接以对象的形式传参,服务端可直接用以下方式接收参数。
修改后,既:正确请求方式参看如下:
FeignClient 接口服务
1 2 3 4 5 | @FeignClient (contextId = "remotePayFormService" , value = "payment-service-system" ) public interface RemotePayFormService { @GetMapping ( "/platPayForm/platPayFormList" ) R<PlatPayform> platFormList( @RequestHeader (SecurityConstants.FROM_SOURCE) String source); } |
服务端代码代码
@RestController @RequestMapping("/platPayForm")
@Slf4j
public class PlatePayMainController extends BaseController {
@Autowired
private IPlatPayFormService platPayFormService;
/**
* 支付集合
*/
@InnerAuth
@GetMapping("/platPayFormList")
public R<PlatPayform> platformList() {
List<PlatFormName> list = platPayFormService.selectPlatPayFormList(null);
if (null != list)
return R.ok(list.get(0));
else
return null;
}
}
}
【推荐】国内首个AI IDE,深度理解中文开发场景,立即下载体验Trae
【推荐】编程新体验,更懂你的AI,立即体验豆包MarsCode编程助手
【推荐】抖音旗下AI助手豆包,你的智能百科全书,全免费不限次数
【推荐】轻量又高性能的 SSH 工具 IShell:AI 加持,快人一步
· 阿里最新开源QwQ-32B,效果媲美deepseek-r1满血版,部署成本又又又降低了!
· SQL Server 2025 AI相关能力初探
· AI编程工具终极对决:字节Trae VS Cursor,谁才是开发者新宠?
· 开源Multi-agent AI智能体框架aevatar.ai,欢迎大家贡献代码
· Manus重磅发布:全球首款通用AI代理技术深度解析与实战指南