bash linux中的cURL命令返回http响应代码

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/22078563/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 09:43:59  来源:igfitidea点击:

cURL Command in linux to return http response code

linuxbashhttpcurl

提问by user3178889

Please i want to use the cURL command in linux OS to return as a result just the http response code which is "200" if it is okey

请我想在 linux 操作系统中使用 cURL 命令返回结果只是 http 响应代码是“200”,如果它是好的

am using that command:

正在使用该命令:

curl -I -L domain.com

but this is returning for me a full text like this

但这为我返回了这样的全文

HTTP/1.1 **200** OK
Date: Thu, 27 Feb 2014 19:32:45 GMT
Server: Apache/2.2.25 (Unix) mod_ssl/2.2.25 OpenSSL/1.0.0-fips mod_auth_passthrough/2.1 mod_bwlimited/1.4 FrontPage/5.0.2.2635 PHP/5.4.19
X-Powered-By: PHP/5.4.19
Set-Cookie: PHPSESSID=bb8aabf4a5419dbd20d56b285199f865; path=/
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Cache-Control: no-store, no-cache, must-revalidate, post-check=0, pre-check=0
Pragma: no-cache
Vary: Accept-Encoding,User-Agent
Content-Type: text/html

so please i just need the response code and not the whole text

所以请我只需要响应代码而不是整个文本

Regards

问候

回答by Sabuj Hassan

curl -s -o out.html -w '%{http_code}' http://www.example.com

回答by Nigel

Running the following will supress the output so you won't have any cleanup.

运行以下将抑制输出,因此您将不会进行任何清理。

curl -s -o /dev/null -w '%{http_code}' 127.0.0.1:80

Example above uses localhost and port 80

上面的示例使用本地主机和端口 80