首页 > 解决方案 > 如何使用 curl 发送列表?

问题描述

后端编码如下:

  @POST
  @Path("/resource")
  @Produces(MediaType.APPLICATION_JSON)
  @Consumes(MediaType.APPLICATION_JSON)
  public Response dailyBilling(
      final List<String> students)
      throws Exception {
     ....
  }

我应该如何发送 curl 数据,我会在后端接受它作为列表?

使用以下 curl 我得到 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"
}

标签: javacurl

解决方案


[]数组在 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 

推荐阅读