【发布时间】:2016-07-31 12:38:28
【问题描述】:
无法使用 curl 将字符串 id 数组发布到 Spring mvc 控制器,因为它正在抛出 400 状态。
控制器方法:
@RequestMapping(value="/evidencesbyIds",method = RequestMethod.POST)
@ResponseBody
public Map<String, Object> getEvidenceByIds(@RequestBody String[] ids){
// body here
}
CURL 命令:
curl -H "Content-type: application/json" -X POST -d '{"ids":["1","2"]}' http://localhost:8080/vt/evidencesbyIds
curl -H "Content-type: application/json" -X POST -d "{"ids":["1","2"]}" http://localhost:8080/vt/evidencesbyIds
curl -H "Content-type: application/json" -X POST -d "{"ids":[\"1\",\"2\"]}" http://localhost:8080/vt/evidencesbyIds
curl -H "Content-type: application/json" -X POST -d "{\"ids\":[\"1\",\"2\"]}" http://localhost:8080/vt/evidencesbyIds
我多次尝试执行 curl 命令,但它们抛出的状态为 400,异常为
"Can not deserialize instance of java.lang.String[] out of START_OBJECT token\n at"
【问题讨论】:
标签: json spring-mvc curl spring-boot spring-4