简体   繁体   English

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

[英]cURL Command in linux to return http response code

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问候

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM