¿Faraday 0.8.X es compatible con el cliente Typhoeus?
apoyo OK;)
Hmm puse:
conn = Faraday.new (url, ssl: {verificar: falso}) hacer | constructor |
builder.response: follow_redirects,: limit => 3,: standards_compliant => false,: cookie =>: all
constructor Adaptador: Typhoeus
fin
Solicitud enviada pero con net_http!
¿Cómo puedo cambiar a Typhoeus de em_http?
En 0.7.X tyhoeus funcionó bien.
Mi seguimiento de pila:
https://gist.github.com/3743068
Configuré el adaptador typhoeus o em_http, pero en los registros:
/home/johnbat26/.rvm/gems/ruby-1.9. 3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb : 54: en new'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in
create_request '
/home/johnbat26/.rvm/gems/ruby-1.9. 3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb : 74: en perform_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:37:in
llamada '
el servidor obtiene una respuesta con el estado 503 pero net_http obtiene un error:
Error
método indefinido `strip 'para nil: NilClass
Estás inicializando una conexión de Faraday como esta:
conn = Faraday.new(url, ssl: {verify: false}) do |builder|
builder.response :follow_redirects, :limit => 3, :standards_compliant => false, :cookie => :all
builder.adapter :typhoeus
end
Se ve bien. Pero, ¿está utilizando la misma conexión para realizar solicitudes? No nos ha mostrado el código con el que realiza solicitudes utilizando Faraday. Quizás esté usando dos conexiones de Faraday diferentes.
Consejo: intente usar follow_redirects solo con las opciones predeterminadas:
builder.response :follow_redirects
Veo en el modo de depuración que el objeto conn usa el adaptador Typhoeus, pero en los registros veo net_http? ¿Por qué?
Yo uso el siguiente código:
require 'faraday'
require 'faraday_middleware'
require 'em-http'
require 'typhoeus'
module MediationHelper
# Parameters:
# url = args[:url]
# method = args[:method] || :post
# adapter = args[:adapter] || :net_http
# body = args[:body] || ""
# params = args[:params]
# authentication = args[:auth]
# headers = args[:headers] || {'Content-Type' => 'text/xml; charset=utf-8'}
# timeout = args[:timeout] || 60
# open_timeout = args[:open_timeout] || 60
#
def self.send_http_request(args)
url = args[:url]
method = args[:method] || :post
adapter = args[:adapter] || :net_http
params = args[:params]
body = args[:body] || ""
authentication = args[:auth]
headers = args[:headers] || {'Content-Type' => 'text/xml; charset=utf-8'}
timeout = args[:timeout] || 60
open_timeout = args[:open_timeout] || 60
conn = Faraday.new(url, ssl: {verify: false}) do |conn|
conn.response :follow_redirects
conn.adapter adapter
end
conn.basic_auth(args[:username], args[:password]) if authentication
response = conn.send(method) do |req|
req.headers.update headers
req.body = body
req.params = params if params
req.options = {
:timeout => timeout, # open/read timeout Integer in seconds
:open_timeout => open_timeout, # read timeout Integer in seconds
}
end
response
end
end
a continuación invoco esto:
response_for_login_request = MediationHelper.send_http_request(:url => url,
:body => login_request_xml,
:adapter => :typhoeus
:headers => {'Content-Type' => "text/xml; charset=utf-8",
'Cookie' => my__cookie,
'SOAPAction' => '""'})
Lo puse:
conn.response: follow_redirects
y todavía aparece el error:
Excepción
NoMethodError
Error
método indefinido `strip 'para nil: NilClass
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1435:in `block in initialize_http_header'
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1433:in `each'
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1433:in `initialize_http_header'
/home/johnbat26/.rvm/rubies/ruby-1.9.3-p194/lib/ruby/1.9.1/net/http.rb:1862:in `initialize'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in `new'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:54:in `create_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:74:in `perform_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/adapter/net_http.rb:37:in `call'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday_middleware-0.8.8/lib/faraday_middleware/response/follow_redirects.rb:76:in `perform_with_redirection'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday_middleware-0.8.8/lib/faraday_middleware/response/follow_redirects.rb:65:in `call'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/connection.rb:226:in `run_request'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/faraday-0.8.4/lib/faraday/connection.rb:99:in `post'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/helpers/mediation_helper.rb:50:in `send_http_request'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/helpers/broadworks_helper.rb:81:in `authenticate'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/helpers/broadworks_helper.rb:121:in `init_broadworks_session'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/jobs/webex_requests_job.rb:24:in `block in perform'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/nokogiri-1.5.5/lib/nokogiri/xml/node_set.rb:239:in `block in each'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/nokogiri-1.5.5/lib/nokogiri/xml/node_set.rb:238:in `upto'
/home/johnbat26/.rvm/gems/ruby-1.9.3-p194@webex/gems/nokogiri-1.5.5/lib/nokogiri/xml/node_set.rb:238:in `each'
/home/coding/projects/idea_projects/tsp-bwks-mediation/app/jobs/webex_requests_job.rb:18:in `perform'
Perdón. Es mi error.
Hago 2 solicitudes y me olvido de la segunda solicitud con el adaptador predeterminado.
Con tifón este error no aparece.
Pero, ¿qué hacer con el adaptador net_http y su error: método indefinido `strip 'para nil: NilClass ?
Lo siento, olvidé responder a esto. Probablemente estaba pasando un valor de encabezado que era nulo y net_http estaba tratando de procesar el valor de encabezado como una cadena.
Para solucionarlo, asegúrese de que cualquier encabezado que pase realmente tenga un valor de cadena.
Comentario más útil
Lo siento, olvidé responder a esto. Probablemente estaba pasando un valor de encabezado que era nulo y net_http estaba tratando de procesar el valor de encabezado como una cadena.
Para solucionarlo, asegúrese de que cualquier encabezado que pase realmente tenga un valor de cadena.