谁能提供使用Digest auth使用HTTPARTY的示例?我找不到网上的例子,希望有人能提供一些帮助。谢谢。

有帮助吗?

解决方案

您可以使用 digest_auth 定义班级时的方法

class Foo
  include HTTParty
  digest_auth 'username', 'password'
end

其他提示

罗布的答案对我有用,但是还有另一种影响整个班级的方式。因此,您可以更改每个呼叫的值。

以下是从 httparty文档:

class Twitter
  include HTTParty
  base_uri 'twitter.com'

  def initialize(u, p)
    @auth = {:username => u, :password => p}
  end

  def post(text)
    options = { :body => {:status => text}, :digest_auth => @auth }
    self.class.post('/statuses/update.json', options)
  end
end

看到 digest_auth 部分?我从原始示例中更改了 basic_auth.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top