我在帖子请求中收到此错误:
undefined method `headers' for HTTP:Module
我正在使用这个宝石:https://github.com/httprb/http.rb
这是我的行动:
def upgrade
require "uri"
require "net/https"
@tokenPagamento = params[:tokenPagamento]
@teste = Gyoku.xml(
:integracao => {:metodo => params[:metodo], :forma_pagamento => {:cartao => {:parcelas => 1}}, :token_pagamento => params[:tokenPagamento]})
xml_doc = Nokogiri::XML(@teste,nil,'UTF-8')
params = {'dados' => xml_doc, 'tokenPagamento' => @tokenPagamento, 'token' => '1233A569C5DD32C0F96410A6C82E04543F81369C'}
HTTP.headers(:accept => "multipart/form-data; charset=utf-8").post('https://go.gerencianet.com.br/teste/api/checkout/pagar/xml', :body => params)
end
错误在最后一行
答案 0 :(得分:3)
您似乎在两个不同的HTTP模块之间存在名称空间冲突。创建一个包含以下内容的Gemfile:
source 'https://rubygems.org'
gem "http", github: "httprb/http.rb"
运行:
bundle install
bundle exec irb
之后你就可以了
HTTP.headers(:accept => "multipart/form-data; charset=utf-8")