网络命令 curl

curl 是 UNIX 里经典的命令行程序。它支持众多的网络协议。可以用来做简单 HTTP 请求测试。

发送 HTTP 请求

curl https://blog.tongdelove.com
<!doctype html>
<html lang="zh-CN" class="respect-color-scheme-preference">
<head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1" />
    <title>吴文斌的博客 – Just another WordPress site</title>
    ...

获取返回头信息

curl https://blog.tongdelove.com -I

获取返回头详细信息

curl https://blog.tongdelove.com -I -v

发送 POST 请求

curl -X POST https://blog.tongdelove.com -d "{\"name\": \"wenbin\"}"

设置请求头

curl -H "User-Agent: custom" https://blog.tongdelove.com

通过 cookies 连续请求, -c cookie-file 可以保存网站返回的 cookie 信息到文件中, -b cookies 可以读取存储的 cookie

curl -L -c cookies https://blog.tongdelove.com
curl -L -b cookies https://blog.tongdelove.com

发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注