1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116
| #!/bin/bash # # BASICS #
# help curl -h # help curl --help # same as -h curl --manual # whole man page
# verbose curl -v # verbose curl -vv # even more verbose
# redirect output to the file curl http://url/file > file # write to file instead of stdout curl -o file http://url/file curl --output file http://url/file # write output to a file named as the remote file curl -o file http://url/file curl --output file http://url/file # execute remote script bash <(curl -s http://url/myscript.sh)
# download headers curl -I url # display header
# basic authentification curl --user username:password http://example.com/ curl -u username:password http://example.com/
# SSL # -k, --insecure allow insecure server connections when using SSL curl -k https://server_with_self_signed_cert/endpoint curl --insecure https://server_with_self_signed_cert/endpoint
# HTTP request # -X, --request <command> specify request command to use # example: curl -X GET http://url/endpoint
# HTTP header # -H, --header <header/@file> pass custom header(s) to server # example: curl -H 'user-agent: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/80.0.3987.163 Safari/537.36' http://url/endpoing
# HTTP POST data # -d, --data <data> HTTP POST data # -d, --data @data HTTP POST data from file # example: curl -d '{json}' -H 'Content-Type: application/json' http://url/endpoint
# config file curl -K file # #or curl --config file # $HOME/.curlrc
# # WRITE OUT PARAMETERS #
# -w, --write-out <format> Use output FORMAT after completion # example: curl -w %{size_header} --silent -o /dev/null http://gogle.com # print size of header when you accessing google.com
# FORMAT supported: # %{content_type} # %{filename_effective} # This is only meaningful if curl is told to write to a file with # the --remote-name or --output option. It's most useful in combination # with the --remote-header-name option. # %{ftp_entry_path} # %{response_code} # %{http_connect} # to a curl CONNECT request. # %{local_ip} # be either IPv4 or IPv6 # %{local_port} # %{num_connects} # %{num_redirects} # %{redirect_url} # was made without -L to follow redirects. # %{remote_ip} # either IPv4 or IPv6. # %{remote_port} # %{size_download} # %{size_header} # %{size_request} # %{size_upload} # %{speed_download} # in bytes per second. # %{speed_upload} # bytes per second. # %{ssl_verify_result} # 0 means the verification was successful. # %{time_appconnect} # to the remote host was completed. # %{time_connect} # host (or proxy) was completed. # %{time_namelookup} # %{time_pretransfer} # to begin. This includes all pre-transfer commands and negotiations that are specific to # the particular protocol(s) involved. # %{time_redirect} # pre-transfer and transfer before the final transaction was started. time_redirect shows # the complete execution time for multiple redirections. # %{time_starttransfer} # be transferred. This includes time_pretransfer and also the time the server needed # to calculate the result. # %{time_total} # with millisecond resolution. # %{url_effective} # to follow Location: headers (with -L)
|