【发布时间】:2019-07-16 14:13:02
【问题描述】:
我已经定义了一个接受字符串值作为请求主体参数的方法,如下所示
@RequestMapping(value="/stringParam",method=RequestMethod.POST,consumes=MediaType.TEXT_PLAIN)
public String stringMethod(@RequestBody String stringParam){
return stringParam;
}
我尝试使用以下 curl 命令调用该端点
curl -X POST "http://localhost:7979/choudhury-rest/rest/book/stringParam" -d '\"ravi\"' -H "Content-Type: application/json"
这给了我这个错误
The request sent by the client was syntactically incorrect.
之后,我尝试了另一种方式
curl -X POST "http://localhost:7979/choudhury-rest/rest/book/stringParam" -d 'stringParam=\"ravi\"' -H "Content-Type: application/json"
这也给了我这个错误
The request sent by the client was syntactically incorrect.
谁能帮助我如何调用该方法(我不知道我们是否可以定义一个接受原始值(int、long 等)作为请求主体参数的 rest 方法)
【问题讨论】:
-
尝试用
{括起您的数据,并用:替换=例如:-d '{"stringParam":"ravi"}' -
“我不知道我们是否可以定义一个接受原始值作为请求主体参数的 rest 方法” - String 在 Java 中不是原始类型。
标签: java spring web-services curl postman