我正在尝试在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
可能导致此错误的原因是什么?
答案 0 :(得分:1)
需要改写HTTP.headers("Content-Type" => "application/xml")
。