SpringBoot-Mock方式发送http post请求,参数无法正确设置到请求方法体中

问题描述:
使用Spring Mock的方式发送post请求,参数没有正确被设置到请求方法体中,导致发送请求到后台无法正常获取参数

原始代码如下:

RequestBuilder request = post("/loggers/logger.controller").content(JSONObject.toJSONString(map));

问题原因:

调用content()方法之前,没有指定contentType类型


解决方法:指定contentType类型为MediaType.APPLICATION_JSON

request = post("/loggers/logger.controller").contentType(MediaType.APPLICATION_JSON).content(JSONObject.toJSONString(map));


猜你喜欢

转载自blog.csdn.net/ignorewho/article/details/80625506