1   require 'net/https'
 2   require 'uri'
 3 
 4   def post_api(api, args)
 5     uri = URI.parse api
 6     http = Net::HTTP.new(uri.host, uri.port)
 7     http.use_ssl = true
 8     req = Net::HTTP::Post.new(uri.request_uri)
 9     req.set_form_data(args)
10     response = http.request(req)
11     JSON.load(response.body)
12   end
13 
14   def get_api(api, args)
15     uri = URI.parse api
16     uri.query = args.collect { |a| "#{a[0]}=#{URI::encode(a[1].to_s)}" }.join('&')
17     http = Net::HTTP.new(uri.host, uri.port)
18     http.use_ssl = true
19     req = Net::HTTP::Get.new(uri.request_uri)
20     response = http.request(req)
21     JSON.load(response.body)
22   end

 

相关文章:

  • 2022-02-08
  • 2021-06-08
  • 2021-11-19
  • 2021-10-11
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2021-06-05
  • 2021-05-21
  • 2022-12-23
相关资源
相似解决方案