k_vishwanath
k_vishwanath

Reputation: 1585

How to send line break using curl?

I'm trying to create confluence page for each file present in one of the directory. I'm using the below curl command to achieve it

$ 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';

This is how it looks when seen in debug mode

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';

I have even tested with this option --data-binary, it didn't work.

I want the file (test.txt) content to be reflected as-is in the confluence page i.e it should retain new line as-is.

It did not work even after putting \n like the below

"storage": { "value": "foo\nbar" }

Any suggestion how to achieve this using curl?

Upvotes: 0

Views: 280

Answers (1)

Daniel Stenberg
Daniel Stenberg

Reputation: 58004

--data-binary will preserve and pass on all white space characters, including newlines while the ordinary -d/--data option will not. It will not introduce any of them by itself though so you need to make sure your data includes them.

Also, please avoid -X POST with -d as it's unnecessary at best, causing problems at worst.

verify

If you want to verify that your POST is exactly the way you want it to be, I would recommend adding --trace-ascii dump.txt to your command line and then check that dump.txt file after the fact and verify that the body was sent exactly the way you wanted it to.

Upvotes: 1

Related Questions