如何使用curl发送换行符?

如何使用curl发送换行符?,curl,confluence,Curl,Confluence,我正在尝试为其中一个目录中的每个文件创建合流页面。我使用下面的curl命令来实现它 $ cat test.txt foo bar curl -i -X POST -H "Content-Type:application/json" -u username:password -d '{ "ancestors": [ { "id": "65601" } ], "body": { "storage": { "value": "'"$(cat test.txt)"'", "representati

我正在尝试为其中一个目录中的每个文件创建合流页面。我使用下面的curl命令来实现它

$ cat test.txt
foo
bar

curl -i -X POST -H "Content-Type:application/json" -u username:password  -d  '{ "ancestors": [ { "id": "65601" } ], "body": { "storage": { "value": "'"$(cat test.txt)"'", "representation": "storage" } }, "space": { "key": "TEST" }, "status": "current", "title": "Page1", "type": "page" }' 'http://localhost:8090/rest/api/content';
这是在调试模式下看到的结果

curl -i -X POST -H "Content-Type:application/json" -u username:password  -d  '{ "ancestors": [ { "id": "65601" } ], "body": { "storage": { "value": "foo
bar", "representation": "storage" } }, "space": { "key": "TEST" }, "status": "current", "title": "Page1", "type": "page" }' 'http://localhost:8090/rest/api/content';
我甚至测试过这个选项——数据二进制,它不起作用

我希望文件(test.txt)的内容能够在confluence页面中按原样反映出来,即它应该按原样保留新行

即使像下面这样放置\n之后,它也不起作用

"storage": { "value": "foo\nbar" }
任何关于如何使用curl实现此目的的建议?

--data binary
将保留并传递所有空白字符,包括换行符,而普通的
-d/--data
选项将不保留。虽然它本身不会引入任何一个,但是您需要确保您的数据中包含它们

另外,请避免使用
-d
发布
-X POST
,因为这充其量是不必要的,最坏的情况下会导致问题

验证
如果你想验证你的帖子是否符合你的要求,我建议在命令行中添加
--trace ascii dump.txt
,然后检查
dump.txt
文件,并验证正文是否按照您希望的方式发送。

这是一种POST方法,对于特定的API调用,正文是必须的。我的答案是。。嗯,答案!