0

我正在尝试将我的网络应用程序连接到 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)

请给我一些提示来解决这个问题。

4

1 回答 1

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'=>'2','key' => @merchant_key,'command'=>command,'hash'=>hash,'var1'=>input_array_var) http.use_ssl = 真实响应 = http.request(request)

于 2014-12-09T07:08:22.110 回答