Tôi nghĩ rằng -f
tùy chọn để curl
làm những gì bạn muốn:
-f
, --fail
(HTTP) Fail silently (no output at all) on server errors. This is mostly done to better enable scripts etc to better deal with failed attempts. In normal cases when an HTTP server fails to deliver a document, it returns an HTML document stating so (which often also describes why and more). This flag will prevent curl from outputting that and return error 22. [...]
Tuy nhiên, nếu câu trả lời là thực sự là một 301 hoặc 302 chuyển hướng, mà vẫn được lưu lại, ngay cả khi đích của nó sẽ gây ra một lỗi :
$ curl -fO http://google.com/aoeu
$ cat aoeu
<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="http://www.google.com/aoeu">here</A>.
</BODY></HTML>
để thực hiện theo chuyển hướng đến ngõ cụt của nó, cũng cung cấp cho các -L
tùy chọn:
-L
, --location
(HTTP/HTTPS) If the server reports that the requested page has moved to a different location (indicated with a Location: header and a 3XX response code), this option will make curl redo the request on the new place. [...]
Theo như tôi có thể nhìn thấy Tháng Mười là người duy nhất thực sự đọc các câu hỏi và trả lời nó. Mọi người khác đã cho bạn các kỹ thuật mà sẽ * không bao giờ bao giờ * tải xuống bất cứ điều gì, hoặc họ nói để cuộn của riêng bạn. Bạn có nên chấp nhận câu trả lời * thực * duy nhất mà bạn đã đưa ra không? – iconoclast