ネット:: HTTP ::無断 - どのように私は、WWW-Authenticateヘッダで入手できますか?
-
25-09-2019 - |
質問
...
以下のコードを考えますNet::HTTP.start('localhost', 4000) do |http|
#
# usual stuff omitted for clarity
#
@response = http.request(req)
end
...(行儀)サーバー場合は401(不正な)応答を返し、どのように私はWWW_Authenticateヘッダ?
で入手できますか私が持って最善の解決策は、すべての良いではないです...
class Net::HTTPUnauthorized
def get_header(h)
_return = nil
target = h.upcase
self.header.each_header do |k, v|
if k.upcase == target
_return = v
break
end
end
_return
end
end
クリス
解決
一つのオプション
は、ラックとNet::HTTP
をラップ halorgiumのラッククライアントを、使用することです終点。あなたでしょうその後、相互に作用し、それはRackアプリケーションであるかのように、リモート・サーバとのます:
response = Rack::Client.get("http://localhost:4000/foo/bar.baz")
response.code
# => 401
response.headers['WWW-Authenticate']
# => 'Basic realm="Control Panel"'
所属していません StackOverflow