连接到payU时出现问题

时间:2014-04-04 09:16:39

标签: ruby-on-rails ruby web-services payment-gateway payu

我正在尝试将我的网络应用程序连接到PayU,我的代码是

require 'net/http'
require 'json'

uri = URI('https://test.payu.in/merchant/postservice')
req = Net::HTTP::Post.new(uri, initheader = {'Content-Type' =>'application/json'})

req.body = {key: "some key", command: "save_user_card", hash: "some code", var1: "some code",
var2: "dummy",
var3: "CC",
var4: "AMEX",
var5: "some name",
var6: "card number",
var7: "05",
var8: "2017"}.to_json

res = Net::HTTP.start(uri.hostname, uri.port) do |http|
  http.request(req)
end

,我得到的错误信息是

net/http/response.rb:41:in `read_status_line': wrong status line: "<!DOCTYPE HTML PUBLIC \"-//IETF//DTD HTML 2.0//EN\">" (Net::HTTPBadResponse)

请提供一些解决此问题的提示。

1 个答案:

答案 0 :(得分:1)

由于url有https,请使用request = URI.parse(URI.encode(request.strip))http = Net :: HTTP.new(request.host,request.port)request = Net :: HTTP :: post.new(request.request_uri)request.set_form_data('form'=&gt;'2','key'=&gt; @ merchant_key,'command'=&gt;命令,'hash'=&gt; hash,'var1' =&gt; input_array_var)http.use_ssl = true response = http.request(request)