I'd like to add an XML file to my JSON request body in a CURL command. This is what I have right now
data=$(cat testdata.xml)
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "data": ''"$(echo $data)"''}' 'http://...'
However this sends { data: '$(echo $data)' } } instead of actually fetching the file.
If I take out the outer single quotes around $(echo $data) like this:
data=$(cat testdata.xml)
curl -X POST --header 'Content-Type: application/json' --header 'Accept: application/json' -d '{ "data": '"$(echo $data)"'}' 'http://...'
Then I encounter error Unexpected token < in JSON at position 10
because the server is reading
'{ "data": <?xml version="1.0" encoding="UTF-8"?> - <note> <to>Tove</to> <from>Jani</from> <heading>Reminder</heading> <body>Don\'t forget me this weekend!</body> </note>}',
How do I fix this? Note that I do NOT want to convert to JSON first. I only want to send the stringified xml file in body.
-Foption to submit it as multipart/mime, reading from a file or a pipe?-d "{ data : \"$data\"}"