Faraday: Faraday.get dan auth dasar

Dibuat pada 23 Okt 2014  ·  5Komentar  ·  Sumber: lostisland/faraday

I can't seem to get Faraday.get to accept the user:pass@host syntax from a url and respect it. Sepertinya saya tidak bisa mendapatkan Faraday.get untuk menerima sintaks pengguna:pass@host dari url dan menghormatinya.

Reproducing with Faraday 0.9.0 Mereproduksi dengan Faraday 0.9.0

Faraday.get("http://foo:bar<strong i="9">@localhost</strong>:3333/test")

The "server" "pelayan"

% 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. Saya mengharapkan tajuk Otentikasi, atau mungkin kesalahan bahwa auth tidak didukung.

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. Saya tidak dapat menemukan dokumen tentang metode Faraday.get di rubydoc.info untuk modul Faraday: http://www.rubydoc.info/gems/faraday/Faraday - jadi saya tidak yakin apa yang saya melakukan kesalahan.

If you point me in the write direction, I am happy to write documentation for this method. Jika Anda mengarahkan saya ke arah penulisan, saya senang menulis dokumentasi untuk metode ini.

en

Komentar yang paling membantu

lebih sederhana:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en

Semua 5 komentar

There are several ways you can set authentication headers with Faraday. Ada beberapa cara Anda dapat mengatur header otentikasi dengan Faraday. One way is to initialize a Faraday::Connection instance and use the basic_auth helper method: Salah satu caranya adalah dengan menginisialisasi instance Faraday::Connection dan menggunakan metode helper 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: Anda juga dapat menggunakan 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: atau:

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 memiliki posting blog yang bagus tentang penggunaan dasar Faraday yang berumur beberapa tahun tetapi masih relevan.

Hope it helps some, Semoga membantu beberapa,
OI OI

en

Thanks @OI for the helpful examples. Terima kasih @OI untuk contoh yang bermanfaat.

@jordansissel For now, please use this form: @jordansissel Untuk saat ini, silakan gunakan formulir ini:

conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass')
conn.get('/foo')

Sorry for the trouble. Maaf untuk masalah ini.

en

Thanks for the pointers, all! Terima kasih atas petunjuknya, semuanya! It helped me get things working. Ini membantu saya mendapatkan hal-hal yang bekerja. ❤️❤️❤️ ❤️❤️❤️

On Tuesday, October 6, 2015, Mislav Marohnić [email protected] Pada hari Selasa, 6 Oktober 2015, Mislav Marohnić [email protected]
wrote: menulis:

Thanks @OI https://github.com/OI for the helpful examples. Terima kasih @OI https://github.com/OI untuk contoh yang bermanfaat.

@jordansissel https://github.com/jordansissel For now, please use this @jordansissel https://github.com/jordansissel Untuk saat ini, silakan gunakan ini
form: membentuk:

conn = Faraday.new('http://example.com') samb = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass') conn.basic_auth('pengguna', 'lulus')
conn.get('/foo') conn.get('/foo')

Sorry for the trouble. Maaf untuk masalah ini.


Reply to this email directly or view it on GitHub Balas email ini secara langsung atau lihat di GitHub
https://github.com/lostisland/faraday/issues/426#issuecomment -145914646. https://github.com/lostisland/faraday/issues/426#issuecomment -145914646.

en

Ini juga dilaporkan sebagai #343.

en

lebih sederhana:
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")

en
Apakah halaman ini membantu?
0 / 5 - 0 peringkat

Masalah terkait

Lewiscowles1986 picture Lewiscowles1986  ·  4Komentar

QuinnWilton picture QuinnWilton  ·  4Komentar

aleksb86 picture aleksb86  ·  3Komentar

jeffb-stell picture jeffb-stell  ·  5Komentar

ioquatix picture ioquatix  ·  4Komentar