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; using System.Threading.Tasks; using System.Net.Sockets; namespace Tlink_Send { class Program {static void Main(string[] args) { Console.WriteLine("江苏xx电气公司OPC-万物云转发工具"); //Console.ReadKey(); System.Timers.Timer maxTimer = new System.Timers.Timer(); maxTimer.Elapsed += new ElapsedEventHandler(Tmr_Elapsed); // 设置引发时间的时间间隔 此处设置为1秒(1000毫秒) maxTimer.Interval = 1000; maxTimer.Enabled = true; //Console.WriteLine(album.ToString()); System.Threading.Thread.Sleep(3000); Console.ReadKey(); } public static string Post(string url) { string result = ""; HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url); req.Method = "POST"; HttpWebResponse resp = (HttpWebResponse)req.GetResponse(); Stream stream = resp.GetResponseStream(); //获取内容 using (StreamReader reader = new StreamReader(stream, Encoding.UTF8)) { result = reader.ReadToEnd(); } return result; } static void Tmr_Elapsed(object sender, ElapsedEventArgs e) { string value = (System.DateTime.Now.Millisecond - 100).ToString(); string message=""; if (Post("http://www.wanwuyun.com/api/hardput?seckey=你自己的&row={'DEV_ID':'meter','VALUE':'" + value + "','NAME':'转发测试'}") == "{\"code\":\"0\"}") { message = "上传到云平台成功" + "上传值为:" + value; } else { message = "上传失败"; } Console.WriteLine(message); Console.ReadKey(); } } }
2020年3月10日
做些别的接口对接,本地数据保存。