1
I'm using cURL to put some data onto a Redmine server. I want to use multiple --data-xxx
options to build a valid XML request body. The command is like this:
curl -H "Content-Type: application/xml" \
-H "X-Redmine-API-Key: $TOKEN" \
-d "<?xml version=\"1.0\"?><wiki_page><text>" \
--data-binary "@$FILE" \
-d "</text></wiki_page>" \
-X PUT http://some.redmine.site.com/projects/someproj/wiki/test.xml
However, as --data
option documented:
If any of these options is used more than once on the same command line, the data pieces specified will be merged together with a separating &-symbol. Thus, using
-d name=daniel -d skill=lousy
would generate a post chunk that looks likename=daniel&skill=lousy
.
I can understand the designer of cURL make it this way to help build a URL with query string. But in this situation, these added &-symbols will make my request XML body malformed. I can prepend "nbsp;" to the value to workaround this when it's after --data
. But when it comes to the usage mixed with a file (--data-binary "@$FILE"
), there are no way to work this out.
Sadly, I've read the manpage carefully and I can tell there is no option to change or suppress the interconnecting character. The only way I can think of is to complete concatenating the string before do curl. – fwonce – 2016-10-10T09:26:39.137
I think this question belongs to StackOverflow.
– Don't Root here plz... – 2016-10-10T09:32:51.730