首页 > Web开发 > 详细

kepware http接口 nodejs开发

时间:2019-03-30 13:43:08      阅读:270      评论:0      收藏:0      [点我收藏+]

 

读取某变量的值(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",
    "Postman-Token": "463c67a9-5615-46b0-aba5-d5de5eac748c"
  }
};

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: 
   { ‘Postman-Token‘: ‘8d08208f-b849-44f0-af60-45126bf88931‘,
     ‘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({
  "Postman-Token": "4e601ec6-97df-4396-98f2-db382f195faa",
  "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",
    "Postman-Token": "afd8f25e-8247-4bb6-9d36-112a022b2882"
  }
};

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: 
   { ‘Postman-Token‘: ‘3babbec1-fc39-4ffa-9ab6-baf6371c17da‘,
     ‘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({
  "Postman-Token": "6ae8d1c2-f538-468a-8e1c-0c530804a12e",
  "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);
});

 

kepware http接口 nodejs开发

原文:https://www.cnblogs.com/dXIOT/p/10626576.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!