是否可以在不实际下载文件的情况下检查文件是否存在?
我有这么大的 (~ 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.
关于ruby - 检查网络文件是否存在,而不下载它?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7655235/