卷曲以返回http状态代码以及响应 [英] Curl to return http status code along with the response
问题描述
我使用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文档获得解决方案,该文档指定使用-
作为输出以将输出输出到stdout。
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}\n" http://localhost
这篇关于卷曲以返回http状态代码以及响应的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!