Ruby 的“open-uri"和“Net:HTTP"gem 有什么区别? [英] What is the difference between Ruby's 'open-uri' and 'Net:HTTP' gems?

查看:21
本文介绍了Ruby 的“open-uri"和“Net:HTTP"gem 有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

看起来这两个 gem 执行的任务非常相似.谁能举例说明一种宝石比另一种更有用的地方?我没有我所指的特定代码,我更想知道每个 gem 的一般用例.我知道这是一个简短的问题,我会根据要求填写空白.谢谢.

It seems like both of these gems perform very similar tasks. Can anyone give examples of where one gem would be more useful than the other? I don't have specific code that I'm referring to, I'm more wondering about general use cases for each gem. I know this is a short question, I will fill in the blanks upon request. Thanks.

推荐答案

它们看起来执行类似任务的原因是 OpenURI 是 Net::HTTP、Net::HTTPS 和 Net::FTP 的包装器.

The reason they look like they perform similar tasks is OpenURI is a wrapper for Net::HTTP, Net::HTTPS, and Net::FTP.

p>

通常,除非您觉得需要较低级别的接口,否则使用 OpenURI 会更好,因为您可以用更少的代码来解决问题.使用 OpenURI,您可以打开 URL/URI 并将其视为文件.

Usually, unless you feel you need a lower level interface, using OpenURI is better as you can get by with less code. Using OpenURI you can open a URL/URI and treat it as a file.

参见:http://www.ruby-doc.org/stdlib-1.9.3/libdoc/open-uri/rdoc/OpenURI.htmlhttp://ruby-doc.org/stdlib-1.9.3//libdoc/net/http/rdoc/Net.html

这篇关于Ruby 的“open-uri"和“Net:HTTP"gem 有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆