读取某变量的值
- require 'uri'
- require 'net/http'
- url = URI("http://127.0.0.1:39321/iotgateway/read?ids=Channel1.Device1.tag1,Channel1.Device1.tag2")
- http = Net::HTTP.new(url.host, url.port)
- request = Net::HTTP::Get.new(url)
- request["Connection"] = 'keep-alive'
- request["Cache-Control"] = 'max-age=0'
- request["Upgrade-Insecure-Requests"] = '1'
- request["User-Agent"] = 'Mozilla/5.0 (Windows NT 6.1; WOW64) ApplewebKit/537.36 (Khtml, like Gecko) Chrome/69.0.3497.81 Safari/537.36'
- request["Accept"] = 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8'
- request["Accept-Encoding"] = 'gzip, deflate, br'
- request["Accept-Language"] = 'zh-CN,zh;q=0.9'
- request["cache-control"] = 'no-cache'
- response = http.request(request)
- puts response.read_body
来源: http://www.bubuko.com/infodetail-3004978.html