為了我的研究,我需要卷曲 fqdns 并獲取它們的狀態代碼。(對于 Http、Https 服務)但是一些 http url 雖然回傳 200 并帶有 cURL,但仍以 https 打開。(請求成功,沒有重定向)
curl -I http://example.example.com/
HTTP/1.1 200 OK
Server: nginx
Date: Mon, 22 Nov 2021 10:43:32 GMT
Content-Type: text/html; charset=UTF-8
Content-Length: 64991
Connection: keep-alive
Keep-Alive: timeout=20
Vary: Accept-Encoding
Expires: Thu, 19 Nov 1981 08:52:00 GMT
Pragma: no-cache
Link: <https://example.example.com/>; rel=shortlink
X-Powered-By: WP Engine
X-Cacheable: SHORT
Vary: Accept-Encoding,Cookie
Cache-Control: max-age=600, must-revalidate
X-Cache: HIT: 10
X-Cache-Group: normal
Accept-Ranges: bytes
如上所示,我收到了 curl 請求的 200 回應。但是我可以在瀏覽器中看到 307 代碼。(在下圖中可用)
Request URL: http://example.example.com/
Request Method: GET
Status Code: 307 Internal Redirect
Referrer Policy: strict-origin-when-cross-origin
我可以用 curl 檢測 307 代碼嗎?(-L 引數不起作用)有什么建議嗎?
uj5u.com熱心網友回復:
curl -w '%{response_code}\n' -so /dev/null $URL
可以這樣測驗:
curl -w '%{response_code}\n' -so /dev/null httpbin.org/status/307
那么問題中的 307 是什么?
正如 Stefan 在單獨的回答中解釋的那樣:這是來自 Chrome的內部訊息,通知您它使用 HSTS。它不是實際的回應代碼。這就是 curl 無法顯示的原因。Chrome 應該更清楚這一點。
高鐵
HSTS 是 HTTPS 服務器要求客戶端不再通過明文 HTTP 聯系他們的一種方式。curl 也支持 HSTS,但是你需要使用--hsts- curl 仍然不會混淆地宣告任何 307 回應代碼。
uj5u.com熱心網友回復:
307 http 狀態實際上并不是服務器發送的回應。這是一個內部重定向,您的瀏覽器甚至在將請求發送到服務器之前為您做的事情。這就是為什么它不會出現在 curl 中。這是您瀏覽器的一項功能。cURL在發送未更改的請求時要可靠得多。
在處理 HSTS(HTTP 嚴格傳輸安全)的安全功能時,通常會遇到 307(特別是因為您提到 https 重定向)內部重定向,其全部目的是確保您永遠不會將未加密的 http 請求發送到服務器想通過加密的 https 進行通信。
看到這個。
轉載請註明出處,本文鏈接:https://www.uj5u.com/qiye/367419.html
下一篇:在GO中使用net/http代理
