最佳 CURLing RoR 方法
我有以下 PHP 代码。我正在寻找将其转换为 Ruby 的最佳方法。我研究了几种方法,包括 open-uri 以及遏制和包装器遏制-fu 库。 open-uri 看起来不太好,但我真的很喜欢遏制-fu 方法。但是,我有一种感觉,使用两个库太过分了,必须有一种更简单的方法来完成这段代码正在做的事情。
#Setup connection
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $resource_uri);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERPWD, $site_public_key . ":" . $site_private_key);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_FAILONERROR, 0);
#Send request
$result_json = curl_exec($curl)
I have the following piece of code in PHP. I'm looking for the best way to convert it to Ruby. I've looked at a few approaches, including open-uri and the curb and wrapper curb-fu libraries. open-uri doesn't look very good, but I really like the curb-fu approach. But, I have a feeling using two libraries for this is overkill, there has to be a simpler way to accomplish what this piece of code is doing.
#Setup connection
$curl = curl_init();
curl_setopt($curl, CURLOPT_URL, $resource_uri);
curl_setopt($curl, CURLOPT_HEADER, 0);
curl_setopt($curl, CURLOPT_USERPWD, $site_public_key . ":" . $site_private_key);
curl_setopt($curl, CURLOPT_TIMEOUT, 15);
curl_setopt($curl, CURLOPT_VERBOSE, 0);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 1);
curl_setopt($curl, CURLOPT_FAILONERROR, 0);
#Send request
$result_json = curl_exec($curl)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
最好的选择是使用 rest-client。它的 api 非常酷且轻量级:
或者如果你不需要身份验证,你可以简单地执行以下操作:
Your best bet is to use rest-client. Its api is really cool and lightweight :
or if you don't need auth you can simply do :