卷曲以返回http状态代码以及响应

编程入门 行业动态 更新时间:2024-10-10 16:20:31
本文介绍了卷曲以返回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 localhost

要获得响应,我使用命令

To get the response, I use the command

curl 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 - 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" localhost

更多推荐

卷曲以返回http状态代码以及响应

本文发布于:2023-11-26 01:53:18,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1632172.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:卷曲   状态   代码   http

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!