我已尝试过以下操作,但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"})
有什么建议吗?
答案 0 :(得分:4)
您可以将其作为标题发送:
client = HTTPClient.new
auth = Base64.strict_encode64("user:secret")
client.get_async(full_url, {:id => hash[:id]}, {'Authorization' => auth})