后端的编码如下:
@POST
@Path("/resource")
@Produces(MediaType.APPLICATION_JSON)
@Consumes(MediaType.APPLICATION_JSON)
public Response dailyBilling(
final List<String> students)
throws Exception {
....
}
我应该如何发送curl数据,该数据将在后端作为List接受?
使用以下卷曲我得到400:
curl --digest -u ameya379+beet@gmail.com:credentials\
-H 'Content-Type: application/json'\
-X POST -d '{"student1", "student2"}'\
http://localhost:8080/api/somepath/resource
错误:
{
"detail":"Received JSON does not match expected format.",
"error":400,
"errorCode":"INVALID_JSON",
"parameters":[],
"reason":"Bad Request"
}
答案 0 :(得分:6)
在JSON中[]
之间对数组进行编码。
curl --digest -u ameya379+beet@gmail.com:credentials -H 'Content-Type: application/json' -X POST -d '["student1", "student2"]' http://localhost:8080/api/somepath/resource