gpt4 book ai didi

ruby - 检查网络文件是否存在,而不下载它?

转载 作者:数据小太阳 更新时间:2023-10-29 07:11:17 25 4
gpt4 key购买 nike

是否可以在不实际下载文件的情况下检查文件是否存在?

我有这么大的 (~ 40mb) 文件,例如:

http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm

这与 ruby​​ 严格相关,但如果发件人可以设置内容长度就好了。

RestClient.get "http://mirrors.sohu.com/mysql/MySQL-6.0/MySQL-6.0.11-0.glibc23.src.rpm", 
headers: {"Content-Length" => 100}

最佳答案

试试 RestClient.head。 (参见 https://www.rfc-editor.org/rfc/rfc9110.html#name-head)

The HTTP HEAD method is identical to GET except that the server MUST NOT send content in the response. HEAD is used to obtain metadata about the selected representation without transferring its representation data, often for the sake of testing hypertext links or finding recent modifications.

RFC 9110 HTTP Semantics

关于ruby - 检查网络文件是否存在,而不下载它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7655235/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com