Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to send line break with curl?

Tags:

http

curl

newline

I've tried the following to send a line break with curl, but \n is not interpreted by curl.

curl -X PUT -d "my message\n" http://localhost:8000/hello 

How can I send a line break with curl?

like image 691
deamon Avatar asked Oct 06 '10 12:10

deamon


People also ask

How do you break a string line?

The newline character is \n in JavaScript and many other languages. All you need to do is add \n character whenever you require a line break to add a new line to a string.

How do you send a POST request on curl?

To make a POST request with Curl, you can run the Curl command-line tool with the -d or --data command-line option and pass the data as the second argument. Curl will automatically select the HTTP POST method and application/x-www-form-urlencoded content type for the transmitted data.

What is data binary in curl?

--data-binary is a curl SPECIFIC flag for curl itself. it has nothing to do with HTTP web services call specifically, but it's how you "POST" data to the call in the HTTP BODY instead of in the header WHEN using curl.


2 Answers

Sometimes you want to provide the data to be sent verbatim.

The --data-binary option does that.

like image 197
Szocske Avatar answered Sep 29 '22 09:09

Szocske


Your shell is passing \ followed by n rather than a newline to curl rather than "my message\n". Bash has support for another string syntax that supports escape sequences like \n and \t. To use it, start the string with $' and end the string with ':

curl -X PUT -d $'my message\n' http://localhost:8000/hello 

See ANSI-C Quoting in the Bash Reference Manual

like image 23
Benjamin Atkin Avatar answered Sep 29 '22 10:09

Benjamin Atkin