I can't seem to get Faraday.get
to accept the user:pass@host syntax from a url and respect it. Je n'arrive pas à obtenir que Faraday.get
accepte la syntaxe user:pass@host d'une URL et la respecte.
Reproducing with Faraday 0.9.0 Reproduction avec Faraday 0.9.0
Faraday.get("http://foo:bar<strong i="9">@localhost</strong>:3333/test")
The "server" Le serveur"
% 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. Je m'attendais à un en-tête d'authentification, ou peut-être à une erreur indiquant que l'authentification n'était pas prise en charge.
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. Je n'ai pas trouvé de documentation sur la méthode Faraday.get
sur rubydoc.info pour le module Faraday : http://www.rubydoc.info/gems/faraday/Faraday - donc je ne suis pas sûr de ce que je suis mal faire.
If you point me in the write direction, I am happy to write documentation for this method. Si vous me dirigez dans le sens de l'écriture, je serai heureux d'écrire une documentation pour cette méthode.
enThere are several ways you can set authentication headers with Faraday. Il existe plusieurs façons de définir des en-têtes d'authentification avec Faraday. One way is to initialize a Faraday::Connection
instance and use the basic_auth
helper method: Une façon consiste à initialiser une instance Faraday::Connection
et à utiliser la méthode d'assistance 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: Vous pouvez également utiliser le 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: ou alors:
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 a un joli article de blog sur l'utilisation de base de Faraday qui date de quelques années mais qui est toujours d'actualité.
Hope it helps some, J'espère que ça en aidera certains,
OI OI
Thanks @OI for the helpful examples. Merci @OI pour les exemples utiles.
@jordansissel For now, please use this form: @jordansissel Pour l'instant, merci d'utiliser ce formulaire :
conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass')
conn.get('/foo')
Sorry for the trouble. Désolé pour le dérangement.
enThanks for the pointers, all! Merci pour les pointeurs, tous! It helped me get things working. Cela m'a aidé à faire fonctionner les choses. ❤️❤️❤️ ❤️❤️❤️
On Tuesday, October 6, 2015, Mislav Marohnić [email protected] Le mardi 6 octobre 2015, Mislav Marohnić [email protected]
wrote: a écrit:
enThanks @OI https://github.com/OI for the helpful examples. Merci @OI https://github.com/OI pour les exemples utiles.
@jordansissel https://github.com/jordansissel For now, please use this @jordansissel https://github.com/jordansissel Pour l'instant, veuillez utiliser ceci
form: formulaire:conn = Faraday.new('http://example.com') conn = Faraday.new('http://example.com')
conn.basic_auth('user', 'pass') conn.basic_auth('utilisateur', 'pass')
conn.get('/foo') conn.get('/foo')Sorry for the trouble. Désolé pour le dérangement.
— —
Reply to this email directly or view it on GitHub Répondez directement à cet e-mail ou consultez-le sur GitHub
https://github.com/lostisland/faraday/issues/426#issuecomment -145914646. https://github.com/lostisland/faraday/issues/426#issuecomment -145914646.
Cela a également été signalé comme # 343.
enplus simple :
Faraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")
Commentaire le plus utile
plus simple :
enFaraday.get('http://localhost:3000', nil, authorization: "Bearer 1123")