java - 如何使用 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"
}
解决方案
[]
数组在 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
推荐阅读
- c# - 从操作返回模型到视图
- ruby-on-rails - Ruby on Rails:在使用带有 will_paginate 的下拉过滤器之前显示默认结果
- haskell - 无点过滤功能
- python - pyplot:绘制具有多个 Y 值和分类 X 值的散点图
- batch-file - 删除文件夹中的所有文件,但名称中包含的文件除外
- php - AJAX 删除先前定义的 jquery 并再次重新定义 - Jquery 无法处理 AJAX 生成的内容
- javascript - 为什么会这样?
- arangodb - ArangoDB 抛出“HTTP WARNING 最大标头大小”
- android - OnQueryTextChange 不使用 AsyncTask 刷新 RecyclerView 适配器
- python - 注释仅适用于最后绘制的线