• kepware http接口 nodejs开发


    读取某变量的值(native

    var http = require("http");
    
    var options = {
      "method": "GET",
      "hostname": [
        "127",
        "0",
        "0",
        "1"
      ],
      "port": "39321",
      "path": [
        "iotgateway",
        "read"
      ],
      "headers": {
        "Connection": "keep-alive",
        "Cache-Control": "max-age=0",
        "Upgrade-Insecure-Requests": "1",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
      }
    };
    
    var req = http.request(options, function (res) {
      var chunks = [];
    
      res.on("data", function (chunk) {
        chunks.push(chunk);
      });
    
      res.on("end", function () {
        var body = Buffer.concat(chunks);
        console.log(body.toString());
      });
    });
    
    req.end();

    读取某变量的值(request

    var request = require("request");
    
    var options = { method: 'GET',
      url: 'http://127.0.0.1:39321/iotgateway/read',
      qs: { ids: [ 'Channel1.Device1.tag1', 'Channel1.Device1.tag2' ] },
      headers: 
       {'cache-control': 'no-cache',
         'Accept-Language': 'zh-CN,zh;q=0.9',
         'Accept-Encoding': 'gzip, deflate, br',
         Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
         'Upgrade-Insecure-Requests': '1',
         'Cache-Control': 'max-age=0',
         Connection: 'keep-alive' } };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
    
      console.log(body);
    });

    读取某变量的值(unirest

    var unirest = require("unirest");
    
    var req = unirest("GET", "http://127.0.0.1:39321/iotgateway/read");
    
    req.query({
      "ids": [
        "Channel1.Device1.tag1",
        "Channel1.Device1.tag2"
      ]
    });
    
    req.headers({"cache-control": "no-cache",
      "Accept-Language": "zh-CN,zh;q=0.9",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
      "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
      "Upgrade-Insecure-Requests": "1",
      "Cache-Control": "max-age=0",
      "Connection": "keep-alive"
    });
    
    
    req.end(function (res) {
      if (res.error) throw new Error(res.error);
    
      console.log(res.body);
    });

    浏览全部变量(native

    var http = require("http");
    
    var options = {
      "method": "GET",
      "hostname": [
        "127",
        "0",
        "0",
        "1"
      ],
      "port": "39321",
      "path": [
        "iotgateway",
        "browse"
      ],
      "headers": {
        "Connection": "keep-alive",
        "Cache-Control": "max-age=0",
        "Upgrade-Insecure-Requests": "1",
        "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
        "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
        "Accept-Encoding": "gzip, deflate, br",
        "Accept-Language": "zh-CN,zh;q=0.9",
        "cache-control": "no-cache",
      }
    };
    
    var req = http.request(options, function (res) {
      var chunks = [];
    
      res.on("data", function (chunk) {
        chunks.push(chunk);
      });
    
      res.on("end", function () {
        var body = Buffer.concat(chunks);
        console.log(body.toString());
      });
    });
    
    req.end();

    浏览全部变量(request

    var request = require("request");
    
    var options = { method: 'GET',
      url: 'http://127.0.0.1:39321/iotgateway/browse',
      headers: 
       { 'cache-control': 'no-cache',
         'Accept-Language': 'zh-CN,zh;q=0.9',
         'Accept-Encoding': 'gzip, deflate, br',
         Accept: 'text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8',
         'User-Agent': 'Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36',
         'Upgrade-Insecure-Requests': '1',
         'Cache-Control': 'max-age=0',
         Connection: 'keep-alive' } };
    
    request(options, function (error, response, body) {
      if (error) throw new Error(error);
    
      console.log(body);
    });

    浏览全部变量(unirest

    var unirest = require("unirest");
    
    var req = unirest("GET", "http://127.0.0.1:39321/iotgateway/browse");
    
    req.headers({"cache-control": "no-cache",
      "Accept-Language": "zh-CN,zh;q=0.9",
      "Accept-Encoding": "gzip, deflate, br",
      "Accept": "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,image/apng,*/*;q=0.8",
      "User-Agent": "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/69.0.3497.81 Safari/537.36",
      "Upgrade-Insecure-Requests": "1",
      "Cache-Control": "max-age=0",
      "Connection": "keep-alive"
    });
    
    
    req.end(function (res) {
      if (res.error) throw new Error(res.error);
    
      console.log(res.body);
    });
  • 相关阅读:
    MySQL
    关于多因子选股模型的常见问题
    T100 GR 报表常见知识点 (含套版制作)
    Oracle Round 函式 (四捨五入)
    Oracle的字串處理
    改變帳款性質別以利排序沖帳才不會有問題,把19->17,把12->17
    財務月結結帳相關檢核程式
    t100 常用公用變數
    一、自动驾驶行业概述(第一课,新认识)
    第一章 软件体系结构概论
  • 原文地址:https://www.cnblogs.com/dXIOT/p/10626576.html
Copyright © 2020-2023  润新知