首页 > 解决方案 > 如何使用 java spring 在 curl 中处理字符串数组

问题描述

我想实现一个名为 process 的 postmapping 方法,它接收这种调用:

curl -d '["a", "b", "c"]' "http://localhost:8080/process"

所以我用下面的模板实现了 ta 方法:

@RequestMapping(value = "/process", method = RequestMethod.POST, consumes = MediaType.APPLICATION_FORM_URLENCODED_VALUE)
List process(@RequestBody String[] list) {
    ...
}

但我有一个例外。HttpMediaTypeNotSupportedException:不支持内容类型“application/x-www-form-urlencoded;charset=UTF-8”。

如果我删除@RequestBody我的列表变量将只是空。谁能帮我?

标签: javaspring-mvccurl

解决方案


推荐阅读