ruby取url内容并json解码

 
      url = "https://xxx.xxx.com"
      begin
        timeout(10, Errno::ETIMEDOUT) {
          uri = URI.parse(url)
          http = Net::HTTP.new( uri.host, uri.port )
          http.use_ssl = true
          http.verify_mode = OpenSSL::SSL::VERIFY_NONE
          request_obj = Net::HTTP::Get.new( uri.request_uri )
          opsdb_response = http.request( request_obj )
          res = ActiveSupport::JSON.decode(opsdb_response.body)
         
        }
      rescue => ex
        logger.error("  error: #{ex.message}") 
        return
      end

你可能感兴趣的:(ruby取url内容并json解码)