如何使用 httparty 模仿卷曲动作

发布于 2024-09-06 06:43:12 字数 819 浏览 10 评论 0原文

我过去很喜欢使用 HTTParty,但现在我遇到了一个我还没有弄清楚的问题。

我正在与之交互的 API 已成功联系,如下所示:

curl -X PUT -d 'id=1175600;status=0' http://www.lingq.com/api_v2/ru/lingqs/?apikey=[long-key]

此 API 中的所有其他功能我在处理我的 gem 时都没有遇到问题,但这一个让我感到悲伤,希望是因为我没有正确使用 httparty gem 。我最初尝试过这个:

class Client
  include HTTParty
  base_uri 'lingq.com/api_v2'

  def method
    self.class.put(path,{:body=>{:id=>1175600,:status=>0},
                         :query=>{:apikey=>@apikey}})
  end
end

没有骰子,它的行为与我通过curl发出GET请求时相同。我还尝试从命令行使用 httparty 只是为了让一些东西开始工作:

httparty -a PUT -d 'id=1175600;status=0' http://www.lingq.com/api_v2/ru/lingqs/?apikey=[long-key]

我得到了“411 Length required”,这是当 :body 选项中没有任何内容时得到的结果。我仍在寻找,但如果有人以前见过这个并且可以提供一些建议,我将不胜感激。

I have loved using HTTParty in the past, but at the moment I'm coming up against a problem I haven't been able to figure out yet.

The API I'm interacting with is successfully contacted like so:

curl -X PUT -d 'id=1175600;status=0' http://www.lingq.com/api_v2/ru/lingqs/?apikey=[long-key]

All other functions in this API I haven't had trouble working into my gem, but this one is giving me grief, hopefully because I'm just not using the httparty gem correctly. I initially tried this:

class Client
  include HTTParty
  base_uri 'lingq.com/api_v2'

  def method
    self.class.put(path,{:body=>{:id=>1175600,:status=>0},
                         :query=>{:apikey=>@apikey}})
  end
end

No dice, it behaves the same as when I issue a GET request through curl. I also tried using httparty from the command line just to get something working to start with:

httparty -a PUT -d 'id=1175600;status=0' http://www.lingq.com/api_v2/ru/lingqs/?apikey=[long-key]

And I get the "411 Length Required", which is what I get when there's nothing in the :body option. I'm still looking, but if anyone has seen this before and could lend some advice I'd appreciate it.

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

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

发布评论

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

评论(1

药祭#氼 2024-09-13 06:43:12

或者,您可以简单地获得“路边”宝石。我不知道您是否愿意切换 HTTP API,但这是一个可行的替代方案,特别是如果您已经喜欢 cURL。

http://rubygems.org/gems/curb

希望我有所帮助。

Or, you could simply get the "curb" gem. I don't know if you would like to switch your HTTP API, but that's a viable alternative, especially if you are already fond of cURL.

http://rubygems.org/gems/curb

Hope I helped.

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