繁体   English   中英

使用Ruby 1.8.7发送带有XML响应的发布请求

[英]send post request with xml response using ruby 1.8.7

我正在尝试自定义接口提供程序qiwi,这是我的代码:

http = Net::HTTP.new('w.qiwi.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
body = {
  :bill_id => "BILL-#{payment.id}",
  :user => 'tel:' + params[:qiwi][:phone],
  :amount => payment.amount,
  :ccy => 'RUB',
  :comment => "",
  :prv_name => 'Company'
}.to_param
key = "Basic " + Base64.encode64s("secret_key")
http.send_request('POST', "/qiwi-notify.php HTTP/1.1", body, {'Accept' => application/xml', 'Authorization' => key})

我需要执行以下操作:

POST /qiwi-notify.php HTTP/1.1
Accept: application/xml
Content-type: application/x-www-form-urlencoded
Authorization: Basic MjA0Mjp0ZXN0Cg==
bill_id=BILL-
1&status=paid&error=0&amount=1.00&user=tel%3A%2B79031811737&prv_nam
e=TEST&ccy=RUB&comment=test&command=bill
Response should XML-doc:
HTTP/1.1 200 OK
Content-Type: text/xml
<?xml version="1.0"?> <result><result_code>0</result_code></result>

我如何在下面实现请求privednny,我的代码不起作用,谢谢

您没有明确说明问题所在,但在查看代码之前,甚至还存在一些问题,甚至无法解释。

:bill_id => "BILL-#{payment.id}"

需要,在最后。

http.send_request('POST', "/qiwi-notify.php HTTP/1.1", body, {'Accept' => application/xml', 'Authorization' => key})

application/xml'之前缺少撇号。

有了这些修复程序,代码最终看起来像

http = Net::HTTP.new('w.qiwi.com', 443)
http.use_ssl = true
http.verify_mode = OpenSSL::SSL::VERIFY_NONE
body = {
  :bill_id => "BILL-#{payment.id}",
  :user => 'tel:' + params[:qiwi][:phone],
  :amount => payment.amount,
  :ccy => 'RUB',
  :comment => "",
  :prv_name => 'Company'
}.to_param
key = "Basic " + Base64.encode64s("secret_key")
http.send_request('POST', "/qiwi-notify.php HTTP/1.1", body, {'Accept' => 'application/xml', 'Authorization' => key})

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM