【问题标题】:HTTParty Digest AuthHTTParty 摘要认证
【发布时间】:2010-12-17 16:08:30
【问题描述】:

谁能提供一个使用 HTTParty 使用摘要身份验证的示例?我在网上找不到例子,希望有人能提供一些帮助。谢谢。

【问题讨论】:

    标签: ruby httparty


    【解决方案1】:

    您可以在定义类时使用digest_auth 方法设置用户名和密码

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

    【讨论】:

      【解决方案2】:

      Rob 的回答对我有用,但还有另一种方式不会影响整个班级。因此,您可以更改每个调用的值。

      以下是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
      

      看到digest_auth 部分了吗?我从原始示例的basic_auth 更改了它。

      【讨论】:

      • 这对我不起作用。尝试使用 monero-rpc-client
      猜你喜欢
      • 2012-07-18
      • 2015-01-04
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-12-24
      • 2018-03-02
      • 2020-09-17
      • 2012-05-26
      相关资源
      最近更新 更多