curl

curl 从主机环境发送 HTTP/HTTPS 请求,显示状态、响应头和正文,可提交方法、数据、Cookie 与 Basic Auth,并能保存响应或在编辑器中打开。

网络版本 1.2.5稳定
lil-terminal

概览

当你需要知道远程端点从服务器侧实际如何响应时使用 curl:可检查 API、重定向、响应头、IPv4/IPv6,也能在没有系统 shell 的情况下保存响应。

请求、响应与执行位置

curl 运行在主机服务器上,而不是本地浏览器中。先从简单 GET 或仅查看响应头开始,再按需加入正文、认证和诊断参数;-k 会明确关闭证书验证。

语法

lil-terminal
curl <url|host|me> [options]

参考

curl me

使用当前主机

curl example.com

发送 GET 请求并显示状态和正文

curl example.com -I

仅显示最终响应头

curl example.com -s [file]

保存响应;省略名称时使用 URL 文件名

curl example.com -X POST -d "a=1"

发送请求正文

-X <method>

设置 HTTP 方法

-d <data>

设置请求正文;默认 POST

-H "Name: value"

添加请求头;可重复指定

-u <user>

通过隐藏密码输入使用 HTTP Basic 身份验证

-c '{"name":"value"}'

从 JSON 对象发送 cookie

-s [file] | -o <file>

将响应保存到主机

-a

追加而非替换;需要 -s 或 -o

-i

包含最终响应头

-I

仅显示最终响应头

-j

以结构化 JSON 显示响应

-edit @edit

在文本编辑器中打开响应正文

-code @code

在代码编辑器中打开响应正文

-t [seconds]

使用 5 秒或 1 到 300 秒的自定义超时

-T

使用 300 秒超时

-4 | -6

在 cURL 可用时使用 IPv4 或 IPv6

-r

不跟随重定向

-k

允许不安全的 TLS 证书

实际使用

先用 curl example.com 查看页面,或用 -I 只看响应头。-i 同时显示响应头和正文,-j 输出结构化 JSON。API 请求可使用 -X、-d 和多个 -H。-s/-o 保存到主机文件,-a 追加;-edit/-code 在已安装的编辑器中打开文本。

限制与安全

-u <user> 单独请求密码,但命令中 -d 的数据或 cookie 可能留在历史记录。默认验证 TLS 证书并最多跟随五次重定向;-k 禁用证书验证,-r 禁用重定向。没有 PHP cURL 时普通请求仍可通过 PHP streams 完成,但 -4/-6 必须使用 cURL。显示上限 8 MiB,保存上限 256 MiB。仅访问获授权的地址,尤其注意内部服务。示例是教学快照。

明确检查 IPv4/IPv6

缺少 PHP cURL 时,curl -4/-6 会明确报错,而不再悄悄忽略地址族选择。

交互式 sandbox 预览

可直接在页面中运行预先准备的示例。结果已预先生成并在浏览器中显示;服务器不会执行任何终端命令。

先检查响应头,再保存响应

安装与管理

安装当前兼容版本。完整功能请选择 Base,精简包请选择 Minimum;已安装模块的更新请使用 upgrade。

Base 与 Minimum 是同一当前模块版本的两个包。

Base 包

安装包含本地参考和全部已发布模式的完整包。

install curl
Minimum 包

安装精简包。该包不包含本地参考;help <cmd> -i 会打开当前服务器参考。

install curl -m
精确公开版本

安装这个确切的已发布版本。

install curl -v 1.2.5
检查或升级

让 upgrade 检查兼容性,仅在需要时替换已安装块。

upgrade curl
删除模块

删除扩展块,不影响核心和其他模块。

install curl -u

示例

示例可复制,但网站不会执行。请先检查路径、权限和破坏性选项。

先检查响应头,再保存响应
curl https://example.com
网络教学示例 — 不发送真实请求
HTTP:		200
URL:		https://example.com/

<!doctype html>
<html>…</html>
使用当前主机
curl me
网络教学示例 — 不发送真实请求
HTTP:		200
URL:		https://example.com/

<!doctype html>
<html>…</html>
仅显示最终响应头
curl https://example.com -I
网络教学示例 — 不发送真实请求
HTTP/2 200
content-type: text/html; charset=UTF-8
cache-control: max-age=86000
包含最终响应头
curl https://example.com -i
网络教学示例 — 不发送真实请求
HTTP/2 200
content-type: text/html; charset=UTF-8

<!doctype html>
<html>…</html>
以结构化 JSON 显示响应
curl https://example.com -j
网络教学示例 — 不发送真实请求
{
  "status": 200,
  "url": "https://example.com/",
  "headers": [
    "HTTP/2 200",
    "content-type: text/html; charset=UTF-8"
  ],
  "body": "<html>…</html>"
}
发送请求正文
curl https://example.com -X POST -d "name=lil"
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Example response to a POST request; the server may reject POST or return another status.
设置请求正文;默认 POST
curl https://example.com -d "name=lil"
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Example response to a POST request; the server may reject POST or return another status.
添加请求头;可重复指定
curl https://example.com -H "Accept: application/json"
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Request contains custom headers; the remote reply depends on the endpoint.
添加请求头;可重复指定
curl https://example.com -H "Accept: application/json" -H "X-Demo: 1"
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Request contains custom headers; the remote reply depends on the endpoint.
从 JSON 对象发送 cookie
curl https://example.com -c '{"theme":"dark"}'
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Request includes Cookie: theme=dark; the server decides how to respond.
通过隐藏密码输入使用 HTTP Basic 身份验证
curl https://example.com -u demo
网络教学示例 — 不发送真实请求
A separate secret-password prompt appears before the request is sent.
保存响应;省略名称时使用 URL 文件名
curl https://example.com -s
网络教学示例 — 不发送真实请求
sandbox/
  index.html
The response body is saved on the hosting account.
拒绝不受支持的协议
curl https://example.com -s tmp/example.html
网络教学示例 — 不发送真实请求
sandbox/tmp/
  example.html
The response body is saved on the hosting account.
将响应保存到主机
curl https://example.com -o tmp/example.html
网络教学示例 — 不发送真实请求
sandbox/tmp/
  example.html
The response body is saved on the hosting account.
追加而非替换;需要 -s 或 -o
curl https://example.com -o tmp/example.html -a
网络教学示例 — 不发送真实请求
sandbox/tmp/
  example.html
The body is appended to the existing file.
使用 5 秒或 1 到 300 秒的自定义超时
curl https://example.com -t
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Timeout option changes the maximum wait, not the response format.
使用 5 秒或 1 到 300 秒的自定义超时
curl https://example.com -t 2
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Timeout option changes the maximum wait, not the response format.
使用 300 秒超时
curl https://example.com -T
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Timeout option changes the maximum wait, not the response format.
在 cURL 可用时使用 IPv4 或 IPv6
curl https://example.com -4
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Requested IP family IPv4 (requires PHP cURL).
在 cURL 可用时使用 IPv4 或 IPv6
curl https://example.com -6
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Requested IP family IPv6 (requires PHP cURL).
不跟随重定向
curl https://example.com -r
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Redirect following disabled; response status depends on endpoint.
允许不安全的 TLS 证书
curl https://example.com -k
网络教学示例 — 不发送真实请求
HTTP: 200
URL: https://example.com/

Certificate verification disabled for this diagnostic request.
在文本编辑器中打开响应正文
curl https://example.com -edit
网络教学示例 — 不发送真实请求
The installed text editor opens the response in a protected temporary file.
在代码编辑器中打开响应正文
curl https://example.com -code
网络教学示例 — 不发送真实请求
The installed code editor opens the response in a protected temporary file.
以结构化 JSON 显示响应
curl https://example.com -j -code
网络教学示例 — 不发送真实请求
The installed code editor opens the response in a protected temporary file as formatted JSON.
在文本编辑器中打开响应正文
curl https://example.com -edit -s tmp/example.html
网络教学示例 — 不发送真实请求
Editor mode cannot be combined with -s or -o
追加而非替换;需要 -s 或 -o
curl https://example.com -a
网络教学示例 — 不发送真实请求
Append requires an output file
Curl · com
curl ftp://example.com
网络教学示例 — 不发送真实请求
Invalid URL
在 cURL 可用时使用 IPv4 或 IPv6
curl https://example.com -4 -6
网络教学示例 — 不发送真实请求
Choose either IPv4 or IPv6
设置 HTTP 方法
curl https://example.com -X 9bad
网络教学示例 — 不发送真实请求
Invalid HTTP method
添加请求头;可重复指定
curl https://example.com -H "broken"
网络教学示例 — 不发送真实请求
Invalid header
从 JSON 对象发送 cookie
curl https://example.com -c not-json
网络教学示例 — 不发送真实请求
Invalid cookie JSON
使用 5 秒或 1 到 300 秒的自定义超时
curl https://example.com -t 301
网络教学示例 — 不发送真实请求
Invalid timeout
将响应保存到主机
curl https://example.com -o
网络教学示例 — 不发送真实请求
Output file required
在文本编辑器中打开响应正文
curl https://example.com -edit -code
网络教学示例 — 不发送真实请求
Choose one editor

相关文档

当前公开版本

v1.2.52026-10-31

明确检查 IPv4/IPv6

缺少 PHP cURL 时,curl -4/-6 会明确报错,而不再悄悄忽略地址族选择。