无脑解决Content-Type的问题

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/y415616231/article/details/84328986

首先,把地址配置到  http://httpbin.org/post (PS:专门看请求的一个)结果如下

{
    "args":{
    },
    "data":"outcode=SDF12345&time=2018-11-21 17:50:10&source=asd123&content=JNUJ9K9IipMHgTmcvaJ2g4ryNMnbpXYKGjvQgs%2B2OMiZUeQDkB710OEJUOo7sVDbgAywSnPyKj65duhFKRynFnmUgdeenGeKA",
    "files":{
    },
    "form":{
    },
    "headers":{
        "Accept":"text/html, image/gif, image/jpeg, *; q=.2, */*; q=.2",
        "Cache-Control":"no-cache",
        "Connection":"close",
        "Content-Length":"549",
        "Content-Type":"text/html; charset=utf-8",
        "Host":"httpbin.org",
        "Pragma":"no-cache",
        "User-Agent":"Java/1.7.0_45"
    },
    "json":null,
    "origin":"127.0.0.1",
    "url":"http://httpbin.org/post"
}

可以直接看到 Content-Type ,再在@RequestMapping里面用consumes(PS:数组,可以设定多个类型,不过不建议)

@RequestMapping(path = "/add", method = RequestMethod.POST,consumes = {"text/*",MediaType.TEXT_HTML_VALUE}  ) 
 public void add(HttpServletRequest request,HttpServletResponse response) {}
    	
    

但是 如果是 text/html的话。就不要在参数里添加@RequestBody注解,除非他有响应的接受字段~!~!

猜你喜欢

转载自blog.csdn.net/y415616231/article/details/84328986