1

我正在尝试使用以下代码将表单数据发布到 Google Checkout:

x = Net::HTTP.post_form(URI.parse('https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/[merchant_number_here]'), @params)

当我尝试使用此行提交时,出现以下错误:

付款控制器中的 Errno::ECONNRESET#create
连接由对等方重置

关于可能出问题的任何想法?

4

2 回答 2

2

该方法post_form尝试通过 HTTP 连接,即使 uri 是 HTTPS。您需要明确告诉 net/http 应该使用安全连接。下面的脚本应该做你想做的事。您可以使用该set_debug_output方法来调试 Google 返回的响应。

require 'net/http'
require 'net/https'

url = URI.parse('https://checkout.google.com/api/checkout/v2/checkoutForm/Merchant/1234567890')
req = Net::HTTP::Post.new(url.path)

req.set_form_data({'my'=>'params'})
res = Net::HTTP.new(url.host, url.port)
res.use_ssl = true

#send the response to stderr for debugging
res.set_debug_output $stderr

res.start {|http| http.request(req) }
于 2009-12-03T22:25:35.150 回答
0

您需要做更多的事情才能让 Net::HTTP 执行 HTTPS 发布。Paul Goscicki 在他题为“ Ruby 中的自定义 HTTPS 查询”的文章中有一个很好的总结,包括示例代码。

我个人建议调查Mechanize。它使用起来更快、更容易,并且有很多不错的功能,包括跟踪重定向和处理 cookie 的能力。

于 2009-12-02T23:59:56.427 回答