見た: set_form_data POST でのパラメーターのエスケープ、およびRuby on Rails HTTPS Post Bad Request
def send_request(params)
host = "https://hc.mercurydev.net"
uri = URI.parse(host)
http = Net::HTTP.new(uri.host, uri.port)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
xml = build_xml_for_checkout(params)
http.start do |http|
req = Net::HTTP::Post.new('http://www.mercurypay.com/InitializePayment')
header = {'Host' => 'hc.mercurydev.net', 'Content-Type' => 'text/xml; charset=utf-8', 'Content-Length' => 'length', 'SOAPAction' => 'http://www.mercurypay.com/InitializePayment'}
req.set_form_data(header, xml)
response = http.request(req)
end
end
Ruby で独自の投稿リクエストを作成しなければならなかったのはこれが初めてです。何か単純なものが欠けていると確信していますが、何か?
-- xml が 100% 良好であることを確認したので、ヘッダーまたはリクエストの作成方法に何かが含まれている必要があります。
編集: ruby-api-docを見た後: 私はこれを思いついた:
uri = URI.parse(host)
Net::HTTP.start(uri.hostname, uri.port,
:use_ssl => uri.scheme == 'https').start do |http|
req = Net::HTTP::Post.new uri.path
req.body = xml
req.set_form_data(header)
res = http.request req
end
これは、(サーバーを再起動しても) HTTP セッションが開いていることを返します。