Http Post request with content type application/x-www-form-urlencoded not working in Spring

后端 未结 7 1650
逝去的感伤
逝去的感伤 2020-11-27 06:19

Am new to spring currently am trying to do HTTP POST request application/x-www-form-url encoded but when i keep this in my headers then spring not recognizing it an

7条回答
  •  盖世英雄少女心
    2020-11-27 07:06

    The problem is that when we use application/x-www-form-urlencoded, Spring doesn't understand it as a RequestBody. So, if we want to use this we must remove the @RequestBody annotation.

    Then try the following:

    @RequestMapping(value = "/patientdetails", method = RequestMethod.POST,consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
    public @ResponseBody List getPatientDetails(
            PatientProfileDto name) {
    
    
        List list = new ArrayList();
        list = service.getPatient(name);
        return list;
    }
    

    Note that removed the annotation @RequestBody

提交回复
热议问题