From a075070a2826e900b9392c3aecc2a607cf59cf37 Mon Sep 17 00:00:00 2001 From: James Chen Date: Mon, 17 Dec 2018 12:29:37 +0900 Subject: [PATCH] fix: http post request for ruby 2.3 and below --- lib/ckb/api.rb | 9 +++++---- 1 file changed, 5 insertions(+), 4 deletions(-) diff --git a/lib/ckb/api.rb b/lib/ckb/api.rb index cece12a0..7d4e71cd 100644 --- a/lib/ckb/api.rb +++ b/lib/ckb/api.rb @@ -16,10 +16,11 @@ def initialize(host: URL) end def rpc_request(method, params: nil) - response = Net::HTTP.post( - uri, - "{\"id\": 1, \"jsonrpc\": \"2.0\", \"method\": \"#{method}\", \"params\": #{params.to_json}}", - "Content-Type" => "application/json") + http = Net::HTTP.new(uri.host, uri.port) + request = Net::HTTP::Post.new(uri.request_uri) + request.body = { id: 1, jsonrpc: "2.0", method: "#{method}", params: params }.to_json + request["Content-Type"] = "application/json" + response = http.request(request) result = JSON.parse(response.body, symbolize_names: true) if result[:error] raise "jsonrpc error: #{result[:error]}"