ToKeiChun

cURL Cheatsheet

Sep 22nd, 2020 (edited)
275
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 4.33 KB | None | 0 0
  1. #http://cheat.sh/curl
  2. # Download a single file
  3. curl http://path.to.the/file
  4.  
  5. # Download a file and specify a new filename
  6. curl http://example.com/file.zip -o new_file.zip
  7.  
  8. # Download multiple files
  9. curl -O URLOfFirstFile -O URLOfSecondFile
  10.  
  11. # Download all sequentially numbered files (1-24)
  12. curl http://example.com/pic[1-24].jpg
  13.  
  14. # Download a file and follow redirects
  15. curl -L http://example.com/file
  16.  
  17. # Download a file and pass HTTP Authentication
  18. curl -u username:password URL
  19.  
  20. # Download a file with a Proxy
  21. curl -x proxysever.server.com:PORT http://addressiwantto.access
  22.  
  23. # Download a file from FTP
  24. curl -u username:password -O ftp://example.com/pub/file.zip
  25.  
  26. # Get an FTP directory listing
  27. curl ftp://username:password@example.com
  28.  
  29. # Resume a previously failed download
  30. curl -C - -o partial_file.zip http://example.com/file.zip
  31.  
  32. # Fetch only the HTTP headers from a response
  33. curl -I http://example.com
  34.  
  35. # Fetch your external IP and network info as JSON
  36. curl http://ifconfig.me/all/json
  37.  
  38. # Limit the rate of a download
  39. curl --limit-rate 1000B -O http://path.to.the/file
  40.  
  41. # POST to a form
  42. curl -F "name=user" -F "password=test" http://example.com
  43.  
  44. # POST JSON Data
  45. curl -H "Content-Type: application/json" -X POST -d '{"user":"bob","pass":"123"}' http://example.com
  46.  
  47. # POST data from the standard in / share data on sprunge.us
  48. curl -F 'sprunge=<-' sprunge.us
  49.  
  50.  
  51.  
  52.  
  53.  
  54. # https://cheatsheet.dennyzhang.com/cheatsheet-curl-a4
  55. 1.1 Curl Get/Head
  56. Curl head request =
  57. curl -I https://www.google.com
  58.  
  59. Curl head request with verbose =
  60. curl -v -I https://www.google.com
  61.  
  62. Curl with explicit http method =
  63. curl -X GET https://www.google.com
  64.  
  65. Curl without http proxy =
  66. curl --noproxy 127.0.0.1 http://www.stackoverflow.com
  67.  
  68. Curl has no timeout by default =
  69. curl --connect-timeout 10 -I -k https://www.google.com
  70.  
  71. Curl get with extra headers =
  72. curl --verbose --header "Host: www.mytest.com:8182" www.google.com
  73.  
  74. Curl get response with headers =
  75. curl -k -v https://www.google.com
  76.  
  77.  
  78. 1.2 Curl POST
  79. Curl post request =
  80. curl -d "name=username&password=123456" <URL>
  81.  
  82. Curl post send json =
  83. curl <URL> -H "content-type: application/json" -d "{ \"woof\": \"bark\"}"
  84.  
  85.  
  86. 1.3 Curl Advanced
  87. Get my public ip =
  88. curl -L -s http://ipecho.net/plain, curl -L -s http://whatismijnip.nl
  89.  
  90. Curl with credential =
  91. curl -u $username:$password http://repo.dennyzhang.com/README.txt
  92.  
  93. Curl upload =
  94. curl -v -F key1=value1 -F upload=@localfilename <URL>
  95.  
  96. Install curl in alpine linux =
  97. apk add --update curl
  98.  
  99. Curl with http2 =
  100. curl -k -v --http2 https://www.google.com/
  101.  
  102. Curl ftp upload =
  103. curl -T cryptopp552.zip -u test:test ftp://10.32.99.187/
  104.  
  105. Curl ftp download =
  106. curl -u test:test ftp://10.32.99.187/cryptopp552.zip -o cryptopp552.zip
  107.  
  108. Curl upload with credential =
  109. curl -v -u admin:admin123 --upload-file package1.zip http://mysever:8081/dir/package1.zip
  110.  
  111.  
  112. 1.4 Curl Script
  113. Install packages with curl =
  114. curl-install-package.sh
  115.  
  116. Check a website response time =
  117. curl-url-time.sh
  118.  
  119. Beautify json output for curl response =
  120. curl-format-json.sh
  121.  
  122. Curl run remote scripts =
  123. curl-remote-scripts.sh
  124.  
  125.  
  126. 1.5 Wget
  127. Download one url =
  128. wget -O /tmp/google.html https://google.com
  129.  
  130. Download mutiple urls =
  131. wget https://google.com https://bing.com
  132.  
  133. Download a list of urls =
  134. wget -i url-list.txt, url-list.txt
  135.  
  136.  
  137.  
  138.  
  139.  
  140. #https://gist.github.com/Kartones/5ae36f801f3d51ac1be0
  141. XML GET
  142. curl -H "Accept: application/xml" -H "Content-Type: application/xml" -X GET "http://hostname/resource"
  143.  
  144. JSON GET
  145. curl -i -H "Accept: application/json" -H "Content-Type: application/json" -X GET "http://hostname/resource"
  146.  
  147. JSON PUT
  148. curl -i -H 'Content-Type: application/json' -H 'Accept: application/json' -X PUT -d '{"updated_field1":"updated_value1"}' "http://hostname/resourcex"
  149.  
  150. JSON POST uploading a file
  151. curl -i -H 'Accept: application/json' -X POST -F "filename=@/file/path" -F "other_field=its_value" "http://hostname/resource"
  152.  
  153. JSON DELETE
  154. curl -i -H 'Content-Type: application/json' -H 'Accept: application/json' -X DELETE -d '{"key1":"value1"}' "http://hostname/resource"
  155.  
  156. "Debugging mode" (without actual content output):
  157. curl -XGET -vvv http://hostname/resource > dev\null
  158.  
  159. Useful arguments
  160. -k: not check SSL certificates
  161. -L: follow redirects
  162. -v: get verbose output
  163. -V: get headers at output
  164.  
  165.  
  166.  
Add Comment
Please, Sign In to add comment