Faraday: Faraday.getと基本認証

作成日 2014年10月23日  ·  5コメント  ·  ソース: lostisland/faraday

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.書き込みの方向を示していただければ、このメソッドのドキュメントを作成できてうれしいです。

en

最も参考になるコメント

より単純:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en

全てのコメント5件

There 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

en

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.ご迷惑おかけして申し訳ありません。

en

Thanks 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:書きました:

Thanks @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

en

これも#343として報告されました。

en

より単純:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en
このページは役に立ちましたか?
0 / 5 - 0 評価

関連する問題

mattmill30 picture mattmill30  ·  4コメント

mvastola picture mvastola  ·  4コメント

Lewiscowles1986 picture Lewiscowles1986  ·  4コメント

ryanbyon picture ryanbyon  ·  3コメント

olleolleolle picture olleolleolle  ·  5コメント