Skip to content

curl tricks

timeout

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

proxy

As option

sock5

curl -x socks5://192.168.1.1:8888

http

curl -x http://192.168.1.1:8888

As env

export http_proxy="http://192.168.1.1:8888"
export https_proxy="http://192.168.1.1:8888"

curl <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/