Linux中“curl -k -i -X”是什么意思?

Zac*_*Zac 5 linux command-line man api curl

我已阅读 的手册页Curl,但我无法理解这些参数(k、i 和 X)的含义。我看到它在 REST API 调用中使用,但有人可以解释这三个参数的作用吗?文档中没有说清楚。

先感谢您。

ari*_*rif 9

-k, --insecure:如果您正在对使用自签名 SSL 证书的网站进行 curl 操作,则 curl 会给您一个错误,因为curl 无法验证证书。在这种情况下,您可以使用-k--insecure标志跳过证书验证

例子:

[root@arif]$ curl --head https://xxx.xxx.xxx.xxx/login

curl: (60) Peer's Certificate issuer is not recognized. 
More details here: http://curl.haxx.se/docs/sslcerts.html 
curl performs SSL certificate verification by default, using a 
"bundle" of Certificate Authority (CA) public keys (CA certs).
If the default bundle file isn't adequate, you can specify an 
alternate file using the --cacert option.
If this HTTPS server uses a certificate signed by a CA represented 
in the bundle, the certificate verification probably failed 
due to a problem with the certificate (it might be expired, 
or the name might not match the domain name in the URL).
If you'd like to turn off curl's verification of the certificate,
use the -k (or --insecure) option.
Run Code Online (Sandbox Code Playgroud)

[root@arif]$ curl -k --head https://xxx.xxx.xxx.xxx/login

HTTP/1.1 302 Moved Temporarily
Date: Thu, 07 Dec 2017 04:53:44 GMT
Transfer-Encoding: chunked
Location: https://xxx.xxx.xxx.xxx/login 
X-FRAME-OPTIONS: SAMEORIGIN
Set-Cookie: JSESSIONID=xxxxxxxxxxx; path=/; HttpOnly
Run Code Online (Sandbox Code Playgroud)

-i, --include:此标志将包含 http 标头。通常 http 标头由服务器名称、日期、内容类型等组成。

例子:

[root@arif]$ curl https://google.com

<HTML><HEAD><meta http-equiv="content-type" content="text/html charset=utf-8"> <TITLE>301 Moved</TITLE></HEAD><BODY> <H1>301 Moved</H1> The document has moved <A HREF="https://www.google.com/">here</A>. </BODY></HTML>

[root@arif]$ curl -i https://google.com

HTTP/1.1 301 Moved Permanently
Location: https://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Thu, 07 Dec 2017 05:13:44 GMT
Expires: Sat, 06 Jan 2018 05:13:44 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 220
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Alt-Svc: hq=":443"; ma=2592000; quic=51303431; quic=51303339;
quic=51303338; quic=51303337; quic=51303335,quic=":443"; ma=2592000;
v="41,39,38,37,35"
<HTML><HEAD><meta http-equiv="content-.....
Run Code Online (Sandbox Code Playgroud)

-X, --request:此标志将用于向服务器发送自定义请求。大多数时候我们都这样做GETHEAD, 和POST。但是,如果您需要特定的请求,例如PUT, FTPDELETE则可以使用此标志。以下示例将向 google.com 发送删除请求

例子:

[root@arif]$ curl -X DELETE google.com

..........................
<p><b>405.</b> <ins>That’s an error.</ins>
<p>The request method <code>DELETE</code> is inappropriate for the URL
<code>/</code>.  <ins>That’s all we know.</ins>`
Run Code Online (Sandbox Code Playgroud)

  • 我尝试了“curl -X DELETE google.com”。根本没用。google.com 仍然存在。 (3认同)