用 curl 获取随机老爸笑话
从公共 API 以纯文本或 JSON 获取笑话。
运行 curl -s -H "Accept: text/plain" https://icanhazdadjoke.com/,以文本打印笑话。
01命令
命令
$ curl -s -H "Accept: text/plain" https://icanhazdadjoke.com/02作用说明
icanhazdadjoke 使用内容协商:Accept: text/plain 只返回笑话,Accept: application/json 返回结构化数据。按 API 要求设置描述性的 User-Agent,用 /search 可按关键词搜索。
03风险
!注意: 不带 Accept 头会收到 HTML 页面;脚本中务必设置。
04撤销
✓无需撤销——该命令不会改变持久状态。
05来源
- icanhazdadjoke API依据: Documents the Accept header content negotiation and the /api endpoints.
最后验证: 2026-09-20 · 分类: 网络