Linux

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

  • May 19, 2019

我已閱讀 的手冊頁Curl,但我無法理解這些參數(k、i 和 X)的含義。我看到它在 REST API 呼叫中使用,但有人可以解釋一下這三個參數的作用嗎?文件中並不清楚。

先感謝您。

-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.

[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

-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-.....

-X, –request:此標誌將用於向伺服器發送自定義請求。大多數時候,我們做GET,HEADPOST。但是,如果您需要特定的請求,例如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>`

引用自:https://unix.stackexchange.com/questions/409363