传输编码无效

时间:2015-04-17 17:09:52

标签: ruby-on-rails ruby xml ruby-on-rails-4 post

我正在尝试在POST中发送XML。

我正在使用这个宝石:https://github.com/httprb/http.rb

我的代码:

xml_doc  = Nokogiri::XML(@teste,nil,'UTF-8')
resposta =  HTTP.headers(:accept => "Content-Type: application/xml;").post('https://desenvolvedor.moip.com.br/sandbox/ws/alpha/EnviarInstrucao/Unica', :body => xml_doc)

我收到错误:Invalid transfer encoding

在gem中,此错误的来源如下:

def add_body_type_headers
    if @body.is_a?(String) && !@headers["Content-Length"]
      @request_header << "Content-Length: #{@body.bytesize}"
    elsif @body.is_a?(Enumerable) && "chunked" != @headers["Transfer-Encoding"]
      fail(RequestError, "invalid transfer encoding")
    end
  end

可能导致此错误的原因是什么?

1 个答案:

答案 0 :(得分:1)

需要改写HTTP.headers("Content-Type" => "application/xml")