Posting XML through cURL using –data-binary

curl

I have this really typical problem. I have an XML file that I have to post to a server. I was told by the network engineer of that site to use the cURL function. The function that he provided to me was…

curl --data-binary @/opt/somefile.xml http://1.2.3.4/gateway/submit?source=FOO&conversationid=1234567

When I run this command I keep getting the error "Bad URL, returning 400 status"

I have been stuck on this problem for quite a while now and I am getting seriously frustrated. I have tried running…

curl http://1.2.3.4/gateway/submit?source=FOO&conversationid=1234567

and I am getting a response from the machine "Test Message" along with some identification parameters of the host system. What this would probably mean that the URL of the destination is OK and it is being accessed via the cURL command.

Are there any special requirements for sending XML files via --data-binary?
Does the XML need to be formatted in a special way?
Is the syntax of the cURL command incorrect?

Best Answer

The & is interpreted by the shell you should use quotes (') around the URL:

curl --data-binary @/opt/somefile.xml 'http://1.2.3.4/gateway/submit?source=FOO&conversationid=1234567'