zoukankan      html  css  js  c++  java
  • 通过domoticz restful接口更新数据 c# 控制台程序

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Net;
    using System.IO;
    using System.Timers;
    using System.Data;
    using Newtonsoft;
    
    namespace Tlink_Send
    {
        class Program
        {
    
            static void Main(string[] args)
            {
                Console.WriteLine("江苏xx电气公司OPC-domoticz转发工具");
                System.Timers.Timer maxTimer = new System.Timers.Timer();
                maxTimer.Elapsed += new ElapsedEventHandler(Tmr_Elapsed);
                maxTimer.Interval = 1000;
                maxTimer.Enabled = true;
                System.Threading.Thread.Sleep(1000);
                Console.ReadKey();
    
            }
    
            //idx 为设备id
            //svalue 为变量值
    
            static void Tmr_Elapsed(object sender, ElapsedEventArgs e)
            {
                GetWebClient("http://127.0.0.1:8080/json.htm?type=command&param=udevice&idx=" + "1" + "&nvalue=0&svalue=" + (System.DateTime.Now.Millisecond - 666).ToString());
                Console.WriteLine("成功转发");
                Console.ReadKey();
            }
    
            public static string GetWebClient(string url)
            {
                HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(url);
                request.Method = "GET";
                request.ContentType = "application/x-www-form-urlencoded";
                request.Credentials = CredentialCache.DefaultCredentials;
                //获得用户名密码的Base64编码
                string code = Convert.ToBase64String(Encoding.ASCII.GetBytes(string.Format("{0}:{1}", "admin", "admin")));
                //添加Authorization到HTTP头
                request.Headers.Add("Authorization", "Basic " + code);
                HttpWebResponse response = (HttpWebResponse)request.GetResponse();
                StreamReader reader = new StreamReader(response.GetResponseStream());
                string content = reader.ReadToEnd();
                return content;
            }
        }
    }

     2020年3月10日

    下面可以做一些灵活对接的工具,方便做项目。

  • 相关阅读:
    ucoreOS_lab5 实验报告
    ucoreOS_lab4 实验报告
    ucoreOS_lab3 实验报告
    ucoreOS_lab2 实验报告
    Mac OSX(Mac OS10.11) 安装 pwntools 失败的最新解决方案
    [最全算法总结]我是如何将递归算法的复杂度优化到O(1)的
    ucoreOS_lab1 实验报告
    Mac下安装npm全局包提示权限不够
    【新特性速递】将纯色背景转换为内置主题!
    【新特性速递】回发时改变表格标题栏和数据!
  • 原文地址:https://www.cnblogs.com/dXIOT/p/9999858.html
Copyright © 2011-2022 走看看