卷曲以返回 http 状态代码以及响应 [英] Curl to return http status code along with the response

查看:33
本文介绍了卷曲以返回 http 状态代码以及响应的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我使用 curl 来获取 http 标头以查找 http 状态代码并返回响应.我使用命令获取 http 标头

I use curl to get http headers to find http status code and also return response. I get the http headers with the command

curl -I http://localhost

为了得到响应,我使用命令

To get the response, I use the command

curl http://localhost

一旦使用了 -I 标志,我就只得到标头,而不再有响应.有没有办法在一个命令中同时获取 http 响应和标头/http 状态代码?

As soon as use the -I flag, I get only the headers and the response is no longer there. Is there a way to get both the http response and the headers/http status code in in one command?

推荐答案

我能够通过查看指定使用 - 作为输出的 curl 文档来获得解决方案标准输出.

I was able to get a solution by looking at the curl doc which specifies to use - for the output to get the output to stdout.

curl -o - http://localhost

要获得仅包含 http 返回码的响应,我可以这样做

To get the response with just the http return code, I could just do

curl -o /dev/null -s -w "%{http_code}
" http://localhost

这篇关于卷曲以返回 http 状态代码以及响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆