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);
});

猜你喜欢

转载自www.cnblogs.com/dXIOT/p/10626576.html