How to send line break with curl?

前端 未结 9 1023
深忆病人
深忆病人 2020-11-27 15:21

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:         


        
9条回答
  •  栀梦
    栀梦 (楼主)
    2020-11-27 15:35

    (I ended up here with a slightly different question, so I'm just going to post my answer because it might help future explorers)

    My solution applies to people who are sending form-style data, i.e. key/value pairs in a query string. Use the encoded line break, which is %0A, just like how an encoded space is %20. You can use http://meyerweb.com/eric/tools/dencoder/ to convert other symbols.

    So if you want to set the key message to the value:

    line one
    another
    

    you would send

    curl --data "message=line%20one%0Aanother" http://localhost:8000/hello
    

提交回复
热议问题