我能够很好地执行get和post请求,但是当我尝试使用相同的格式执行put请求时,我得到: Zlib :: DataError(块类型无效)
这是回溯
/Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:357:in `finish': invalid block type (Zlib::DataError)
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:357:in `finish'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:262:in `ensure in inflater'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:262:in `inflater'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:274:in `read_body_0'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:201:in `read_body'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:226:in `body'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http/response.rb:163:in `reading_body'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1412:in `block in transport_request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1403:in `catch'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1403:in `transport_request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1376:in `request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1369:in `block in request'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:852:in `start'
from /Users/psi/.rvm/rubies/ruby-2.0.0-p451/lib/ruby/2.0.0/net/http.rb:1367:in `request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:80:in `perform_request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/adapter/net_http.rb:39:in `call'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/request/url_encoded.rb:15:in `call'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/rack_builder.rb:139:in `build_response'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/faraday-0.9.0/lib/faraday/connection.rb:377:in `run_request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.3/lib/oauth2/client.rb:90:in `request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.3/lib/oauth2/access_token.rb:107:in `request'
from /Users/psi/.rvm/gems/ruby-2.0.0-p451/gems/oauth2-0.9.3/lib/oauth2/access_token.rb:128:in `put'
from api_check.rb:50:in `<main>'
这是设置代码
require 'oauth2'
client = OAuth2::Client.new(CLIENTID, CLIENTSECRET,
site: SITE, token_url: TOKENURL)
token = client.client_credentials.get_token
response = token.put(PATH, {body: {params1: PARAM1}})
我正在使用oauth2版本0.9.3 如果我正在执行请求的方式有问题,我没有错误日志的指示。 如果需要更多信息,请告诉我。
答案 0 :(得分:0)
如果我使用不同的法拉第适配器(如EventMachine),我会得到正确的OAuth2 :: Error异常,并带有详细消息而不是破坏。 要更改适配器,请将所需的适配器添加到Gemfile,并在调用OAuth2方法之前添加此行
Faraday.default_adapter = :em_http