开发者

HTTParty Digest Auth

开发者 https://www.devze.com 2023-01-31 07:10 出处:网络
Can anyone 开发者_Python百科provide an example of using HTTParty using digest auth? I can\'t find examples on the net and was hoping someone could provide some help. Thanks.you can set the username an

Can anyone 开发者_Python百科provide an example of using HTTParty using digest auth? I can't find examples on the net and was hoping someone could provide some help. Thanks.


you can set the username and password using the digest_auth method when defining your class

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


Rob's answer worked for me, but there's another way that doesn't affect the entire class. You could thus change the values for each call.

The following is slightly modified from the HTTParty doc:

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

See the digest_auth part? I changed that from the original example's basic_auth.

0

精彩评论

暂无评论...
验证码 换一张
取 消