1

Curl 重定向

 1 year ago
source link: https://www.myfreax.com/curl-redirection/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.
neoserver,ios ssh client

Curl 重定向

Curl 是用于在本地计算机与远程服务器之间传输数据的命令行工具

Updated At 7 Jan 2023 2 min read
By myfreax
Curl 重定向

Curl 重定向

Curl 是用于在本地计算机与远程服务器之间传输数据的命令行工具。使用curl时您可以使用HTTP,HTTPS,SCP SFTPFTP等协议下载或上传数据。

Curl 提供了许多选项,使您可以恢复上传/下载,限制带宽,代理支持,用户身份验证等。

Curl 命令已预安装在大多数Linux发行版。要检查你的Linux发行版是否已安装Curl,请按快捷键CTRL+ALT+T打开终端,键入curl,然后按Enter。

安装 Curl

如果已安装curl,则系统将打印curl: try 'curl --help' or 'curl --manual' for more information

否则终端打印消息curl command not found curl命令未找到。如果你尚未安装Curl,则可以使用发行版的软件包管理器安装curl

如果你的计算机运行的是基于Debian的Linux发行版,例如Ubuntu,Linux Mint等。请运行sudo apt install curl命令安装curl。

如果你的计算机运行的是基于Redhat的Linux发行版,例如CentOS,Fedora等。请运行sudo yum install curl命令安装Curl。

sudo yum install curl
sudo apt install curl

HTTP 重定向

如果尝试在没有 www 的情况下抓取 google.com 主页,你会注意到 Google 返回是301页面的内容,运行命令 curl google.com

从 301 重定向的页面内容中可以看到,google.com 被重定向到 www 版本。并且在默认情况下 Curl 命令不遵循HTTP Location header。

因此你不会获得 Google 主页的源码。要跟随 301 重定向请使用 Curl 命令的-L/--location选项,Curl 命令直到服务器不返回状态码 301 才会终止。

curl -L google.com
curl-command-examples.webp
Linux Curl命令详解教程

About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK