1

When sending over a multi-line file as plain text using curl's -d option, the new lines seem to be ignored:

$ cat test.txt
line 1
line 2

When I send the file as body of a POST request with curl, the lines are glued in one ("body": "line 1line 2"):

$ curl -X POST -H 'Content-type: text/plain' -d @test.txt http://echo.httpkit.com
{
  "method": "POST",
  "uri": "/",
  "path": {
    "name": "/",
    "query": "",
    "params": {}
  },
  "headers": {
    "x-forwarded-for": "104.155.92.247",
    "host": "echo.httpkit.com",
    "user-agent": "curl/7.35.0",
    "accept": "*/*",
    "content-type": "text/plain",
    "content-length": "6"
  },
  "body": "foobar",
  "ip": "127.0.0.1",
  "powered-by": "http://httpkit.com",
  "docs": "http://httpkit.com/echo"
}

What am I doing wrong?

Aleph Aleph
  • 5,215
  • 2
  • 13
  • 28

1 Answers1

0

My fault, found the exact same question. How to send line break with curl?

Need to use --data-binary option:

curl -X POST -H 'Content-type: text/plain' --data-binary @test.txt http://echo.httpkit.com
Community
  • 1
  • 1
Aleph Aleph
  • 5,215
  • 2
  • 13
  • 28