Ruby中类似于cURL的替代品是什么?

71

有没有适用于Ruby的cURL库?

13个回答

4

补充最新答案,HTTPClient 是另一个使用 libcurl 的 Ruby 库,支持并行线程和许多 curl 的好处。我在任何非平凡的应用中都使用 HTTPClient 和 Typhoeus。


2
显而易见的是,Ruby 中的勾号也可以执行 shell 代码。只要你的 Ruby 代码运行在拥有 curl 的 shell 中:
puts `curl http://www.google.com?q=hello`

或者

result = `
  curl -X POST https://www.myurl.com/users \
  -d "name=pat" \
  -d "age=21"
` 
puts result

0

一个漂亮的最小可复现示例,可以复制/粘贴到你的Rails控制台中:

require 'open-uri'
require 'nokogiri'

url = "https://www.example.com"
html_file = URI.open(url)
doc = Nokogiri::HTML(html_file)
doc.css("h1").text
# => "Example Domain"

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接