curl -w,–write-out参数详解

简介: 原文地址:http://www.letuknowit.com/post/17.html 顾名思义,write-out的作用就是输出点什么。curl的-w参数用于在一次完整且成功的操作后输出指定格式的内容到标准输出。

原文地址:http://www.letuknowit.com/post/17.html

顾名思义,write-out的作用就是输出点什么。curl的-w参数用于在一次完整且成功的操作后输出指定格式的内容到标准输出。

输出格式由普通字符串和任意数量的变量组成,输出变量需要按照%{variable_name}的格式,如果需要输出%,double一下即可,即%%,同时,\n是换行,\r是回车,\t是TAB。curl会用合适的值来替代输出格式中的变量,所有可用变量如下:

url_effective 最终获取的url地址,尤其是当你指定给curl的地址存在301跳转,且通过-L继续追踪的情形。

http_code http状态码,如200成功,301转向,404未找到,500服务器错误等。(The numerical response code that was found in the last retrieved HTTP(S) or FTP(s) transfer. In 7.18.2 the alias response_code was added to show the same info.)

http_connect The numerical code that was found in the last response (from a proxy) to a curl CONNECT request. (Added in 7.12.4)

time_total 总时间,按秒计。精确到小数点后三位。 (The total time, in seconds, that the full operation lasted. The time will be displayed with millisecond resolution.)

time_namelookup DNS解析时间,从请求开始到DNS解析完毕所用时间。(The time, in seconds, it took from the start until the name resolving was completed.)

time_connect 连接时间,从开始到建立TCP连接完成所用时间,包括前边DNS解析时间,如果需要单纯的得到连接时间,用这个time_connect时间减去前边time_namelookup时间。以下同理,不再赘述。(The time, in seconds, it took from the start until the TCP connect to the remote host (or proxy) was completed.)

time_appconnect 连接建立完成时间,如SSL/SSH等建立连接或者完成三次握手时间。(The time, in seconds, it took from the start until the SSL/SSH/etc connect/handshake to the remote host was completed. (Added in 7.19.0))

time_pretransfer 从开始到准备传输的时间。(The time, in seconds, it took from the start until the file transfer was just about to begin. This includes all pre-transfer commands and negotiations that are specific to the particular protocol(s) involved.)

time_redirect 重定向时间,包括到最后一次传输前的几次重定向的DNS解析,连接,预传输,传输时间。(The time, in seconds, it took for all redirection steps include name lookup, connect, pretransfer and transfer before the final transaction was started. time_redirect shows the complete execution time for multiple redirections. (Added in 7.12.3))

time_starttransfer 开始传输时间。在发出请求之后,Web 服务器返回数据的第一个字节所用的时间(The time, in seconds, it took from the start until the first byte was just about to be transferred. This includes time_pretransfer and also the time the server needed to calculate the result.)

size_download 下载大小。(The total amount of bytes that were downloaded.)

size_upload 上传大小。(The total amount of bytes that were uploaded.)

size_header  下载的header的大小(The total amount of bytes of the downloaded headers.)

size_request 请求的大小。(The total amount of bytes that were sent in the HTTP request.)

speed_download 下载速度,单位-字节每秒。(The average download speed that curl measured for the complete download. Bytes per second.)

speed_upload 上传速度,单位-字节每秒。(The average upload speed that curl measured for the complete upload. Bytes per second.)

content_type 就是content-Type,不用多说了,这是一个访问我博客首页返回的结果示例(text/html; charset=UTF-8);(The Content-Type of the requested document, if there was any.)

num_connects Number of new connects made in the recent transfer. (Added in 7.12.3)

num_redirects Number of redirects that were followed in the request. (Added in 7.12.3)

redirect_url When a HTTP request was made without -L to follow redirects, this variable will show the actual URL a redirect would take you to. (Added in 7.18.2)

ftp_entry_path The initial path libcurl ended up in when logging on to the remote FTP server. (Added in 7.15.4)

ssl_verify_result ssl认证结果,返回0表示认证成功。( The result of the SSL peer certificate verification that was requested. 0 means the verification was successful. (Added in 7.19.0))

注意:

1、若多次使用-w参数,按最后一个的格式输出。

2、在使用上面变量的时候,注意看后面小括号中的 Added in XXX,这个表示支持该变量curl所需的最低版本,查看curl版本使用curl -V。如果版本不够,curl会提示类似下面的错误。

curl: unknown --write-out variable: 'redirect_url'

参考文档:

1、man curl

2、http://digdeeply.org/archives/05102012.html

目录
相关文章
|
机器学习/深度学习 运维
Moment:又一个开源的时间序列基础模型
MOMENT团队推出Time-series Pile,一个大型公共时间序列数据集,用于预训练首个开源时间序列模型家族。模型基于Transformer,采用遮蔽预训练技术,适用于预测、分类、异常检测和输入任务。研究发现,随机初始化比使用语言模型权重更有效,且直接预训练的模型表现出色。MOMENT改进了Transformer架构,调整了Layer norm并引入关系位置嵌入。模型在长期预测和异常检测中表现优异,但对于数值预测的效果尚不明朗。论文贡献包括开源方法、数据集创建和资源有限情况下的性能评估框架。
1509 0
|
负载均衡 应用服务中间件 Docker
Docker Service 创建
Docker Service 创建
|
算法 Linux 数据安全/隐私保护
Linux权限管理:深入理解setuid、setgid、seteuid和setegid
Linux权限管理:深入理解setuid、setgid、seteuid和setegid
1718 0
|
关系型数据库 MySQL 数据库
阿里云rds简介和如何使用
阿里云关系型数据库服务(RDS)是一种在云端提供的高可用性、可扩展、安全的关系型数据库服务。它支持多种数据库引擎,包括MySQL、PostgreSQL、Oracle等,并提供了丰富的监控、备份、恢复、容灾等功能,帮助企业快速构建和运维高可用、高性能的数据库系统。
3390 0
|
4月前
|
监控 数据可视化 安全
OpenClaw 阿里云/本地可视化看板完整部署:系统监控、任务管理与成本统计一站式方案+免费模型配置
在长期运行OpenClaw(Clawdbot)智能体集群时,非技术人员与团队管理者往往难以通过终端日志判断系统状态:无法直观查看Token消耗、任务执行链路、智能体工作负载、上下文压力与异常阻塞任务。TianyiDataScience团队开源的OpenClaw Control Center提供了一套安全优先、本地优先、中英双语的可视化监控面板,将系统运行数据转化为可观测、可预警、可追溯的可视化指标,同时默认启用强安全策略,避免误操作与数据风险。本文完整说明OpenClaw Control Center的功能架构、安装流程、环境配置、安全策略,并同步提供2026年阿里云轻量服务器、本地MacOS
1796 0
|
Ubuntu 安全 Linux
详述Ubuntu中的/etc/rc.local与/etc/init.d/rc.local文件的不同应用场景
总结一下,`/etc/rc.local`和 `/etc/init.d/rc.local`可以说是系统自定义服务的二人转。在Systemd登基以前,`/etc/rc.local`是大明星,负责在系统启动的最后一刻执行任务。而 `/etc/init.d/rc.local`则扮演着保证 `rc.local`文件内容可以被执行的幕后角色。随着Ubuntu版图的更迭和Systemd的崛起,两者都有所转变,但它们依旧是实现系统自启动自定义命令和程序的得力工具,虽然现在要通过一些额外的设置来唤醒它们的能力。此外,由于Systemd的灵活性和强大,推荐使用更加现代化的Systemd单元(unit)文件来替代这
478 10
|
弹性计算 NoSQL 数据库
阿里云服务器如何备份数据?
阿里云服务器数据备份有多种方法,用户可按需选择。主要方式包括:1)快照备份,创建云盘的时间点拷贝,支持定期备份与数据恢复;2)数据库备份DBS,适用于多种环境的数据库备份,涵盖本地及多云场景;3)云备份Cloud Backup,提供统一灾备平台,支持ECS整机、数据库、文件系统等全方位备份,保障数据安全。
|
机器学习/深度学习 人工智能 自然语言处理
《鱼与熊掌兼得:DataWorks中AI驱动的数据脱敏与可用性平衡术》
在数字化时代,数据成为企业核心资产,驱动业务决策与创新。DataWorks作为大数据处理平台,利用AI技术进行数据脱敏,确保隐私保护的同时维持数据可用性。通过生成对抗网络(GAN)和自然语言处理,DataWorks能生成既保留特征又符合隐私要求的脱敏数据,支持机器学习模型训练。此外,建立数据映射关系和应用数据增强技术,进一步提升脱敏数据的实用性和多样性。尽管面临挑战,DataWorks正不断优化算法,结合新兴技术,实现数据隐私与价值挖掘的平衡,助力数字经济健康发展。
698 29
|
机器学习/深度学习 人工智能 Ubuntu
|
缓存 监控 JavaScript
Vue.js 框架下的性能优化策略与实践
Vue.js 框架下的性能优化策略与实践