用SpringMVC RequestBody获得头

问题描述:

我使用用SpringMVC,这是我的POST方法:用SpringMVC RequestBody获得头

RequestMapping(value = "/test/handler", 
      method = RequestMethod.POST, 
     headers = {"Content-type=application/json"}) 
    public String getOpen(@RequestBody String json, HttpServletRequest request) throws InterruptedException { 

     String result= json;       

     ObjectMapper mapper = new ObjectMapper(); 
     DataJsonMailJet jsonobj = null; 
     try { 

      // read from file, convert it to jsonobj class 
      jsonobj = mapper.readValue(json, DataJsonMailJet.class); 

      // display to console 
      System.out.println(jsonobj); 

     } catch (JsonGenerationException e) { 

      e.printStackTrace(); 

     } catch (JsonMappingException e) { 

      e.printStackTrace(); 

     } catch (IOException e) { 

      e.printStackTrace(); 

     } 


    return (result); 

    } 

的问题是,我的“JSON”对象,甚至还让头部像这样:

------------------------------2fe344dd21f3 
Content-Disposition: form-data; name="0" 

[{"event":"open","time":1467369924, .......}] 
------------------------------2fe344dd21f3-- 

我已尝试拿出“标题”,但没有运气... 有什么建议吗?由于

尝试这样

@RequestMapping(value = "/test/handler", method = RequestMethod.POST) 
public String getOpen(
     @RequestHeader(value="Accept") String accept, 
     @RequestHeader(value="Content-Type") String contentType, 
     @RequestBody String json, 
     HttpServletResponse response) { 

    ... 
    ... 
} 
+0

它给了我下面的错误: 缺少标题“内容处置”的方法参数类型[java.lang.String中] - 缺少标题“内容处置”的方法参数类型[java.lang.String] – Kunal

+1

@Kunal - 请删除它并重试,Content-Disposition是一个响应头,如果需要的话,我们需要在发送响应时设置这个头。 –

+0

我设法解决了错误,谢谢!这是请求发件人的错。他们遇到了一些问题,头部被包含在身体中......谢谢! – Kunal