Search code examples
xmlhttppostcurlcarriage-return

XML carraige returns are gone after posting


I'm a linux user. I have an XML file call config.xml. below is the head of the file:

<?xml version='1.0' encoding='UTF-8'?>
<project>
  <actions/>
  <description></description>
  <logRotator>
    <daysToKeep>-1</daysToKeep>
    <numToKeep>10</numToKeep>
...

I'm trying to post it using:

curl --user "USERNAME:PASSWORD" -X POST -d "@config.xml" -H "Content-Type: text/xml; charset=utf-8" http://example.com

the config.xml gets posted however the content comes out with out carriage return. such as:

<?xml version="1.0" encoding="UTF-8"?><project>  <actions/>  <description/>  <logRotator>    <daysToKeep>-1</daysToKeep>    <numToKeep>10</numToKeep> ...

Tests that have been done so far:

  • I have actually ran "od -tc config.xml" and the original file contains the "\r" character however the posted xml file doesn't contain it.

  • I have tried sending it using the content type "application/xml" and "plain/text" but it is still the same way. (I thought maybe the carriage return would be preserved with the binary or ascii types)

  • I have tried to run unix2dos to maybe add "\n" to the end of the lines which it does (tested using od -tc) however it doesn't resolve the problem either.

Please let me know if I should do anything else?

ps

if it help, this is related to the hudson build server and posting config.xml file for a task that already exists.

Thank you


Solution

  • instead of using curl's -d (or --data) option, use the one that preserves the file:

       --data-binary <data>
              (HTTP) This posts data exactly as specified with no extra pro‐
              cessing whatsoever.