簡體   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