I can't seem to get Faraday.get
to accept the user:pass@host syntax from a url and respect it. Faraday.get
を取得してURLからuser:pass @ host構文を受け入れ、それを尊重することができないようです。
Reproducing with Faraday 0.9.0ファラデー0.9.0で再現
Faraday.get("http://foo:bar<strong i="9">@localhost</strong>:3333/test")
The "server"サーバー"
% nc -l localhost 3333
GET /test HTTP/1.1
User-Agent: Faraday v0.9.0
Accept-Encoding: gzip;q=1.0,deflate;q=0.6,identity;q=0.3
Accept: */*
Connection: close
Host: localhost:3333
I expected an Authentication header, or perhaps an error that auth wasn't supported.認証ヘッダー、または認証がサポートされていないというエラーが予想されました。
I couldn't find docs on the Faraday.get
method on rubydoc.info for the Faraday module: http://www.rubydoc.info/gems/faraday/Faraday - so I'm not sure what I'm doing wrong.ファラデーモジュールのrubydoc.infoのFaraday.get
メソッドに関するドキュメントが見つかりませんでした: http ://www.rubydoc.info/gems/faraday/Faraday-だから私は自分が何であるかわかりません間違ったこと。
If you point me in the write direction, I am happy to write documentation for this method.書き込みの方向を示していただければ、このメソッドのドキュメントを作成できてうれしいです。
enThere are several ways you can set authentication headers with Faraday. Faradayで認証ヘッダーを設定する方法はいくつかあります。 One way is to initialize a Faraday::Connection
instance and use the basic_auth
helper method: 1つの方法は、 Faraday::Connection
インスタンスを初期化し、 basic_auth
ヘルパーメソッドを使用することです。
conn = Faraday.new(url: 'http://example.com') # create a new Connection with base URL
conn.basic_auth('user', 'pass') # set the Authentication header
conn.get('/foo') # GET http://example.com/foo
You could also use middleware:ミドルウェアを使用することもできます。
conn = Faraday.new(url: 'http://example.com') do |builder|
builder.use Faraday::Request::Retry
builder.use Faraday::Request::BasicAuthentication, 'user', 'pass'
builder.use Faraday::Response::Logger
builder.use Faraday::Adapter::NetHttp
end
conn.get('/foo')
or:また:
Faraday.new(url: 'http://example.com') do |builder|
builder.request :retry
builder.request :basic_authentication, 'user', 'pass'
builder.response :logger
builder.adapter :net_http
end
conn.get('/foo')
Intridea has a nice blog post on basic Faraday usage that's a few years old but still relevant. Intrideaには、ファラデーの基本的な使用法に関するすばらしいブログ投稿があります。これは数年前のものですが、それでも関連性があります。
Hope it helps some,それがいくつかの助けになることを願っています、
OI OI
Thanks @OI for the helpful examples.役立つ例を提供してくれた@OIに感謝します。
@jordansissel For now, please use this form: @jordansissel今のところ、次のフォームを使用してください:
conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass')
conn.get('/foo')
Sorry for the trouble.ご迷惑おかけして申し訳ありません。
enThanks for the pointers, all!ポインタをありがとう、すべて! It helped me get things working.それは私が物事を機能させるのに役立ちました。 ❤️❤️❤️ ❤️❤️❤️
On Tuesday, October 6, 2015, Mislav Marohnić [email protected] 2015年10月6日火曜日、 MislavMarohnićnotifications @ github.com
wrote:書きました:
enThanks @OI https://github.com/OI for the helpful examples.役立つ例を提供してくれた@OIhttps://github.com/OIに感謝します。
@jordansissel https://github.com/jordansissel For now, please use this @jordansissel https://github.com/jordansissel今のところ、これを使用してください
form:形:conn = Faraday.new('http://example.com') conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass') conn.basic_auth('user'、'pass')
conn.get('/foo') conn.get('/ foo')Sorry for the trouble.ご迷惑おかけして申し訳ありません。
— —
Reply to this email directly or view it on GitHubこのメールに直接返信するか、GitHubで表示してください
https://github.com/lostisland/faraday/issues/426#issuecomment -145914646. https://github.com/lostisland/faraday/issues/426#issuecomment-145914646 。
これも#343として報告されました。
enより単純:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")
最も参考になるコメント
より単純:
enFaraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")