法拉第超时 [英] Faraday timeout

查看:49
本文介绍了法拉第超时的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在网上搜索了文档和其他地方,似乎无法找到为法拉第设置超时选项的正确方法.有人知道答案吗?

I've searched the docs and other places online and cannot seem to come up with the proper way to set the timeout option for Faraday. Anyone have the answer?

我试过了:

  conn = FaradayStack.build(url)
  conn.headers[:user_agent]   = AppConfig.user_agent
  # conn.options[:timeout]      = 20
  # conn.options[:open_timeout] = 20
  response = conn.get do |req|
    req.options = {
      :timeout      => 20,
      :open_timeout => 20
    }
  end
  response.body

似乎没有任何效果.顺便说一句,如果有区别的话,我正在使用 Typhoeus 适配器.

Nothing seems to be working. BTW, I'm using the Typhoeus adapter if that makes a difference.

推荐答案

好吧,看来我想通了.如果我将超时选项传递给初始化程序,它似乎可以工作:

Well it seems I figured it out. If I pass the timeout option into the initializer, it seems to work:

  options = {
    :timeout      => 20,
    :open_timeout => 20
  }
  conn = FaradayStack.build(url, options)
  conn.headers[:user_agent] = AppConfig.user_agent
  conn.get.body

这篇关于法拉第超时的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆