如何在ruby中使用HttpClient.get_async发送BasicAuth?

时间:2013-06-10 13:24:48

标签: ruby httpclient

我已尝试过以下操作,但BASIC_AUTHENTICATION标志似乎没有在另一端设置,并且收到“401 Unauthorized”错误。

client = HTTPClient.new
client.set_auth(nil, "user", "secret")
client.get_async(full_url, {:id => hash[:id]}, {username: "user", password: "secret"})

# HOWEVER THIS WORKS, non-async
# client.get(full_url, {:id => hash[:id]}, {username: "user", password: "secret"}) 

有什么建议吗?

1 个答案:

答案 0 :(得分:4)

您可以将其作为标题发送:

client    = HTTPClient.new
auth      = Base64.strict_encode64("user:secret")
client.get_async(full_url, {:id => hash[:id]}, {'Authorization' => auth})