RestClient gem 如何在 ruby​​ 中工作

发布于 2025-01-05 23:36:00 字数 497 浏览 2 评论 0原文

我在ruby中使用Rest-client gem。我的代码如下..,

require 'rest_client'

puts RestClient.get 'http://localhost:3000/articles'

puts RestClient.put 'http://localhost:3000/', {:params => {:Bat => 'ball'}}

RestClient.post 'http://localhost:3000/articles', {:params => {:Name => 'list1', 'Content' => 'Article1'}}

我引用在rails应用程序中运行的URL,用户可以使用上面的url创建、删除、编辑、列出文章。对于放置, delete、post、get 方法它会在我的提示中生成 URL 的 html 代码。但它无法通过 ruby​​ 代码插入帖子/从列表中删除项目。 在 RestClient 中可以吗?

I'm using Rest-client gem in ruby.My code is as follows..,

require 'rest_client'

puts RestClient.get 'http://localhost:3000/articles'

puts RestClient.put 'http://localhost:3000/', {:params => {:Bat => 'ball'}}

RestClient.post 'http://localhost:3000/articles', {:params => {:Name => 'list1', 'Content' => 'Article1'}}

I refer the URL which runs in rails application, the user can can create, delete, edit,list the articles using the above url.For put,delete,post,get methods it produces the html code of the URL in my prompt.But it cannnot able to insert the post/delete an item from the list via ruby code.
It is possible in RestClient?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

红尘作伴 2025-01-12 23:36:00

我认为这里的问题是您需要进行身份验证。您可以使用 RestClient 来做到这一点,但您需要链接您的调用。请参阅rest_client自述文件如何执行此操作。

I think the problem here is that you need to be authenticated. You can do that with RestClient but you will need to chain your calls. See the rest_client Readme how to do that.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文