Curl follow HTTP redirect
Curl is a command-line tool for transferring data between a local computer and a remote server
Curl is a command-line tool for transferring data between a local computer and a remote server.
When using curl you can download or upload data using protocols such as HTTP, HTTPS, SCP , SFTP and FTP .
The Curl command is pre-installed on most Linux distributions. To check if your Linux distribution has Curl installed, press the shortcut key CTRL+ALT+T
to open Terminal, type curl
and press Enter.
If curl is installed, the system will print curl: try 'curl --help' or 'curl --manual' for more information
.
Install Curl
Otherwise, the terminal prints the message curl command not found. If you don't have Curl installed, you can install it using your distribution's package manager.
If your computer is running a Debian-based Linux distribution such as Ubuntu, Linux Mint, etc. Please run sudo apt install curl
to install Curl.
If your computer is running a Redhat-based Linux distribution, such as CentOS, Fedora, etc. Please run sudo yum install curl
to install Curl.
sudo yum install curl
sudo apt install curl
Follow HTTP redirection
If you try to scrape the google.com homepage without www
the , you'll notice that Google returns the content of the 301 page, run the command curl google.com
.
As you can see from the page content of the 301 redirect, it google.com
is redirected to the www version. And by default Curl commands don't follow the HTTP Location header.
So you won't get the source code of the Google homepage. To follow a 301 redirect use the -L
/ --location
option of the Curl command, the Curl command will not terminate until the server does not return a status code of 301.
curl -L google.com