2014-01-14 93 views
0

我必須在我的請求中發送兩個XML文檔到UPS API(這是我的原始問題What is the root of this XML document?Ruby + Net :: HTTP:如何在一個POST請求中發送兩個XML文檔?

我該怎麼做?

def make_initial_request 
    uri = URI.parse(UPS_API['confirm_url']) 
    https = Net::HTTP.new(uri.host, uri.port) 
    https.use_ssl = true  

    headers = {'Content-Type' => 'text/xml'} 
    request = Net::HTTP::Post.new(uri.path, headers) 
    request.body = xml_for_initial_request #<-- how do i split this into two documents? 
    #request.body = second_xml_document #<-- i want something like that. could i just use << ? 
    begin 
    response = https.request(request) 
    rescue 
    return nil 
    end 
    puts "response: #{response.code} #{response.message}: #{response.body}" 
    return nil if response.body.include?("Error") 
end 

回答

0

如果API支持它們(ruby gem),您應該使用MIME Multipart消息。 否則只是嘗試連接文件的內容request.body = "#{xml_for_initial_request}\n#{second_xml_document}"