如何使用Ruby通过HTTP下载和保存二进制文件?
网址是http://somedomain.net/flv/sample/sample.flv.
我在Windows平台上,我宁愿不运行任何外部程序.
使用Open :: URI,我可以执行以下操作:
require 'open-uri'
#check status
open('http://google.com').status
#get entire html
open('http://google.com').read
Run Code Online (Sandbox Code Playgroud)
是否可以获取请求的HTTP头,以便可以调试内容,如Curls' curl -I http://google.com?
$ curl -I google.com
HTTP/1.1 301 Moved Permanently
Location: http://www.google.com/
Content-Type: text/html; charset=UTF-8
Date: Mon, 17 Dec 2012 14:28:17 GMT
Expires: Wed, 16 Jan 2013 14:28:17 GMT
Cache-Control: public, max-age=2592000
Server: gws
Content-Length: 219
X-XSS-Protection: 1; mode=block
X-Frame-Options: SAMEORIGIN
Run Code Online (Sandbox Code Playgroud)
这可能吗?