curl command is used to interact with a web server. It can be used to fetch content from or post data to a HTTP endpoint. Consider it to be a command line web browser without a GUI. It can do pretty much everything that a web browser can do except that it:

  • doesn’t display pretty web pages, its a linux cli command afterall
  • doesn’t run javascript on the page

Listed below are the most common usage of curl. Refer to the official documentation for an exhaustive list of options and flags.

Examples

Most basic usage

$ curl http://example.com
#=> issues a GET request and outputs html souce of example.com website

POST request

# With data (-d or --data)
$ curl -d 'username=john&password=secret' http://example.com/login
#=> issues a POST request with POST parameters username=john and password=secret
#   Use this to POST form fields with "content-type: application/x-www-form-urlencoded"

# Without data
$ curl -d '' http://example.com/login.htm
# or
$ curl -X POST http://example.com/login.htm

# Upload file (-F or --form)
$ curl --form "[email protected]" http://example.com/upload-pic

# Upload file as well as desired target filename plus send post params
$ curl --form "[email protected];filename=display-pic.jpg" --form username=john --form password=secret

Curl with proxy

# use a http proxy (-x or --proxy)
$ curl -x http://proxy.company.com:80 http://example.com
or
$ curl -x 127.0.0.1:8080 http://example.com

# or the usual linux way by setting the env variable
$ http_proxy=http://proxy.company.com:80 curl http://example.com
# note that for https webpages, the command will be
$ https_proxy=http://proxy.company.com:80 curl https://example.com