用 curl 获取随机老爸笑话

从公共 API 以纯文本或 JSON 获取笑话。

Linuxcurl 请求网络API低风险
运行 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风险

风险低风险
使用条件curl (preinstalled on most Linux distributions)
!注意: 不带 Accept 头会收到 HTML 页面;脚本中务必设置。

04撤销

✓无需撤销——该命令不会改变持久状态。

05来源

  • icanhazdadjoke API
    icanhazdadjoke.com · vendor-doc · 2026-09-20
    依据: Documents the Accept header content negotiation and the /api endpoints.

最后验证: 2026-09-20 · 分类: 网络

06相关方案