Skip to content

curl tricks

Basics

curl -ks --connection-timeout 5 <URL>

Send multi-line message by json

name="foo"

message="$@"
message="${message//$'\r'/}"  
message="${message//$'\n'/\\n}"

json="{'message':'${message}','name':'$name'}"
json=$(echo "$json" | tr "'" '"')

curl -s -X POST -H "Content-Type: application/json" "$URL" -d "$json"

Basic Authorization

U='YOUR-NAME'
P='YOUR-PASSWORD'
A=$(echo -ne "$U:$P"|base64 --wrap 0)

curl --header "Authorization: Basic $A" http://foo.com/