美文网首页
解决springboot中只支持get请求,无法支持post请求

解决springboot中只支持get请求,无法支持post请求

作者: 帮我的鸵鸟盖个章 | 来源:发表于2021-02-25 20:57 被阅读0次

    解决springboot中只支持get请求,无法支持post请求

    报错信息如下: 405

    405.png

    相关类如下:

    @RestController
    @RequestMapping
    public class HttpServiceController {
    
        @Autowired
        private HttpSecretReport httpSecretReport;
        @Autowired
        private HttpSecretRecording httpSecretRecording;
    
        @PostMapping(value="/secret_report", produces="application/json;charset=UTF-8")
        @ResponseBody
        public Object getCallRecordBySecretReport1(@RequestBody String requestBody){
            return httpSecretReport.dealHttpSecretReport(HttpMethodNameEnum.HTTP_SECRET_REPORT_HOME_DISPATCH.code,requestBody);
        }
    }
    

    解决办法:@RequestMapping 增加post方法支持 @RequestMapping(value = "/call_record",method = {RequestMethod.GET,RequestMethod.POST})

    @RestController
    @RequestMapping(value = "/call_record",method = {RequestMethod.GET,RequestMethod.POST})
    public class HttpServiceController {
    
        @Autowired
        private HttpSecretReport httpSecretReport;
        @Autowired
        private HttpSecretRecording httpSecretRecording;
    
        @PostMapping(value="/secret_report", produces="application/json;charset=UTF-8")
        @ResponseBody
        public Object getCallRecordBySecretReport1(@RequestBody String requestBody){
            return httpSecretReport.dealHttpSecretReport(HttpMethodNameEnum.HTTP_SECRET_REPORT_HOME_DISPATCH.code,requestBody);
        }
    }
    

    完美解决

    相关文章

      网友评论

          本文标题:解决springboot中只支持get请求,无法支持post请求

          本文链接:https://www.haomeiwen.com/subject/qktpfltx.html