更新时间:2023-11-26 21:18:28
这是什么如果我想要简单的代码,我会这样做:
This is what I'd do if I want simple code:
require 'open-uri'
str = open('http://example.com')
str.content_type #=> "text/html"
最大的好处是重定向之后。
The big advantage is it follows redirects.
如果要检查一堆URL,您可能要在处理完之后在句柄上调用 close
找到了想要的东西。
If you're checking a bunch of URLs you might want to call close
on the handles after you've found what you want.