Skip to content

Instantly share code, notes, and snippets.

@nextsummer33
Created July 22, 2013 09:09
Show Gist options
  • Save nextsummer33/6052463 to your computer and use it in GitHub Desktop.
Save nextsummer33/6052463 to your computer and use it in GitHub Desktop.

Curl Cheat Sheet

  1. Get a html content from an url

     curl http://www.exmaple.com
    
  2. -o Get a html content and save it to a file

     curl -o example.html http://www.exmaple.com
    
  3. -x Using Proxy

     curl -x 123.45.67.89:1080 -o example.html http://www.exmaple.com
    
  4. -D Dump a cookie

     curl -x 123.45.67.89:1080 -o example.html -D cookie0001.txt http://www.exmaple.com
    
  5. -b Add cookie to http header

     curl -x 123.45.67.89:1080 -o page1.html -D cookie0002.txt -b cookie0001.txt http://www.linuxidc.com
    
  6. -H Add a value to http header

     curl -H "key: value" www.example.com
    
  7. -O Save a file from server with a same name

     curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen1.JPG
    
  8. Usign Regular Expression to make a matched file name changes its name

     curl -O http://cgi2.tky.3web.ne.jp/~zzh/screen[1-10].JPG
     curl -o #2-#1.jpg http://cgi2.tky.3web.ne.jp/~{zzh,nick}/[001-201].JPG
    

    Original: ~zzh/001.JPG -> After downloaded:001-zzh.JPG Original: ~nick/001.JPG -> After downloaded:001-nick.JPG

  9. -u Setting FTP username and password

     curl -u name:passwd ftp://ip:port/path/file
     curl ftp://name:passwd@ip:port/path/file
    
  10. -T Upload a file

    curl -T localfile -u name:passwd ftp://upload_site:port/path/
    curl -T localfile http://cgi2.tky.3web.ne.jp/~zzh/abc.cgi
    
  11. GET Request GET REQUEST

    curl http://www.linuxidc.com/login.cgi?user=nickwolfe&password=12345
    
  12. POST Request POST REQUEST

    curl -d "user=nickwolfe&password=12345" http://www.linuxidc.com/login.cgi
    

    An example that is used to post a form to server. Besides upload a file.

    <form action="http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi" enctype="multipar/form-data" method="POST">
    <input name="upload" type="file"/>
    <input name="nick" type="submit" value="go"/></form>
    

    -F For a form request, we have to do so

    curl -F upload=@localfile -F nick=go http://cgi2.tky.3web.ne.jp/~zzh/up_file.cgi
    
  13. https local certificate

    curl -E localcert.pem https://remote_server
    
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment