Post

Curl

Curl

Basic Usage

  1. Retrieve a Web Page
    1
    
    curl http://example.com
    
  2. Save the Output to a File
    1
    
    curl -o output.html http://example.com
    
  3. Follow Redirects
    1
    
    curl -L http://example.com
    
  4. HTTP Methods
  • GET Request
    1
    
      curl -X GET http://example.com
    
  • POST Request
    1
    
      curl -X POST -d "param1=value1&param2=value2" http://example.com
    
  • PUT Request
    1
    
      curl -X PUT -d "param1=value1&param2=value2" http://example.com/resource/1
    
  • DELETE Request
    1
    
      curl -X DELETE http://example.com/resource/1
    

Headers and Authentication

  1. Set Custom Headers
    1
    
    curl -H "Content-Type: application/json" http://example.com
    
  2. Send a User-Agent Header
    1
    
    curl -A "Mozilla/5.0" http://example.com
    
  3. Basic Authentication
    1
    
    curl -u username:password http://example.com
    
  4. Bearer Token Authentication
    1
    
    curl -H "Authorization: Bearer your_token" http://example.com
    

Data and Files

  1. Send Form Data
    1
    
    curl -F "name=John" -F "file=@photo.jpg" http://example.com/upload
    
  2. Send JSON Data
    1
    
    curl -X POST -H "Content-Type: application/json" -d '{"key1":"value1", "key2":"value2"}' http://example.com/api
    
  3. Upload a File
    1
    
    curl -T file.txt ftp://example.com/upload/
    

Advanced Usage

  1. Handle Cookies
    1
    
    curl -c cookies.txt -b cookies.txt http://example.com
    
  2. Verbose Output
    1
    
    curl -v http://example.com
    
  3. Limit Download Rate
    1
    
    curl --limit-rate 100K http://example.com
    
  4. Specify a Proxy
    1
    
    curl -x http://proxy.example.com:8080 http://example.com
    
  5. Insecure Connections (ignore SSL certificate errors)
    1
    
    curl -k https://example.com
    
  6. Download Multiple Files
    1
    
    curl -O http://example.com/file1 -O http://example.com/file2
    
This post is licensed under CC BY 4.0 by the author.