網站在curl上收到「太多重定向」回應,但在瀏覽器中運作良好(chrome)

網站在curl上收到「太多重定向」回應,但在瀏覽器中運作良好(chrome)

我遇到過這樣的情況:URL 在瀏覽器中打開正常,但在curl.

如下例所示,我的 WSL2 實例使用curl 發出的請求取自 bash 腳本:

curl -sSL  https://www.bricomarche.net -o /dev/null -w "%{response_code} %{url_effective} \n"

curl: (47) Maximum (50) redirects followed
302 https://intermarche.queue-it.net/?c=intermarche&e=bricoprodkuserv2&ver=v3-java-3.5.1&cver=45&cid=fr-CA&l=BRICOMARCHE&t=https%3A%2F%2Fwww.bricomarche.com%2F 

請注意,為簡單起見,我在上面的命令中省略了從 Chrome 瀏覽器複製的自訂使用者代理程式。結果是一樣的。

但是,如果我嘗試在 Chrome 瀏覽器中開啟上述 URL - 它工作正常。

我在 URL 中遇到的情況相同https://shop.mercury.co.nz- 在瀏覽器中打開正常,但在curl中得到太多重定向:

$  curl -sSL https://shop.mercury.co.nz -o /dev/null -w "%{response_code} %{url_effective} \n"
curl: (47) Maximum (50) redirects followed     
302 https://shop.mercury.co.nz/nz/join/prepare 

知道如何修復捲曲嗎?

答案1

顯然,至少在某些情況下這是一個 cookie 問題。

添加-b non-existing作為參數到curl 請求以某種方式有助於解決問題。

curl -sLI -b non-existing https://the_site -o /dev/null -w "%{response_code} %{url_effective} \n"

相關內容