【发布时间】:2016-04-23 05:25:11
【问题描述】:
考虑下面的 curl 命令,是否可以在 JSON 中允许换行符(没有缩小)并直接在 bash 中执行(Mac/Ubuntu)
curl -0 -v -X POST http://www.example.com/api/users \
-H "Expect:" \
-H 'Content-Type: text/json; charset=utf-8' \
-d \
'
{
"field1": "test",
"field2": {
"foo": "bar"
}
}'
当我运行上面的命令时,second { 似乎发生了错误
如何修复上述命令?
更新:实际上我之前能够运行该命令而没有问题,不知道为什么最近会出现问题。
【问题讨论】:
-
你能告诉我们更多关于错误的信息吗?您的示例在我的系统上“按原样”运行。
mymac > bash --version GNU bash, version 3.2.57(1)-release (x86_64-apple-darwin15) Copyright (C) 2007 Free Software Foundation, Inc. -
是的,也适用于我:
GNU bash, version 4.3.42(1)-release -
也可以查看ANSI C-like string syntax:
echo $'here is a newline:\nand here is a tab:\t' -
application/json是 JSON 数据的正确媒体类型 -- 请参阅 RFC4627