Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send list using curl?

Tags:

java

curl

The backend is coded like this:

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

How should I send curl data, which would me accepted as a List on backend ?

Using the following curl i get 400:

curl --digest -u [email protected]:credentials\
-H 'Content-Type: application/json'\
-X POST -d '{"student1", "student2"}'\
http://localhost:8080/api/somepath/resource

Error:

{
    "detail":"Received JSON does not match expected format.",
    "error":400,
    "errorCode":"INVALID_JSON",
    "parameters":[],
    "reason":"Bad Request"
}
like image 921
JavaDeveloper Avatar asked Oct 18 '25 09:10

JavaDeveloper


1 Answers

Arrays are encoded between [] in JSON.

curl  --digest -u [email protected]:credentials  -H 'Content-Type: application/json' -X POST -d '["student1", "student2"]' http://localhost:8080/api/somepath/resource 
like image 117
W.K.S Avatar answered Oct 19 '25 22:10

W.K.S



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!