跳转至
本文阅读量

curl 命令用法

简述

常用场景

发起请求并将响应保存为文件

通过 -o 指定输出文件

curl https://www.iyiou.com/analysis/2019031194436 -o $(date +%Y%m%d_%H%M%S).html

如何发起 POST 等请求

如何提交表单数据

如何发起 JSON 请求

如何增加自定义头

如何打印详细的 HTTP 头信息

curl -i https://www.bing.com

结果如下

$ curl -i https://www.bing.com
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100   137  100   137    0     0    453      0 --:--:-- --:--:-- --:--:--   453HTTP/2 302
cache-control: private
content-length: 137
content-type: text/html; charset=utf-8
location: https://cn.bing.com/
set-cookie: SNRHOP=TS=637656580627946881&I=1; domain=.bing.com; path=/
x-snr-routing: 1
x-cache: CONFIG_NOCACHE
x-msedge-ref: Ref A: 25619FAE4F1A42C684F9E5C7F2BA1555 Ref B: BJ1EDGE0619 Ref C: 2021-08-27T10:47:37Z
set-cookie: _EDGE_S=F=1&SID=267A9F286EAD61A317CF8F886FEE60C2; path=/; httponly; domain=bing.com
set-cookie: _EDGE_V=1; path=/; httponly; expires=Wed, 21-Sep-2022 10:47:37 GMT; domain=bing.com
set-cookie: MUID=017213179BB76C6633F203B79AF46D0E; samesite=none; path=/; secure; expires=Wed, 21-Sep-2022 10:47:37 GMT; domain=bing.com
set-cookie: MUIDB=017213179BB76C6633F203B79AF46D0E; path=/; httponly; expires=Wed, 21-Sep-2022 10:47:37 GMT
date: Fri, 27 Aug 2021 10:47:37 GMT

<html><head><title>Object moved</title></head><body>
<h2>Object moved to <a href="https://cn.bing.com/">here</a>.</h2>
</body></html>

如何上传文件

类似工具