Files
Web_IoTBase_Sever_Prod/Common/HttpSend.cs
2025-12-11 14:04:39 +08:00

46 lines
1.8 KiB
C#
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
using System;
using System.Collections.Generic;
using System.Configuration;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Microsoft.VisualBasic;
using RestSharp;
namespace LogCap.Common
{
public class HttpSend
{
public static readonly string debug_log_report_url = ReadConfig.Instance.get_debug_log_report_url;
public static readonly string debug_log_report_mqtt_topic = ReadConfig.Instance.get_debug_log_report_mqtt_topic;
public static RestClient client1 = new RestClient(debug_log_report_url);
public static async void SendLog(string MyCommandType, long hotel_code, int host_id, string roomnumber, string hostnumber, string WWW_IP, int WWW_Port, string lan_ip, int lan_port, string mac, string send_or_receive, string dataHex)
{
try
{
string ti = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss.fff");
string mm = "";
string str = Newtonsoft.Json.JsonConvert.SerializeObject(mm);
//Console.WriteLine("发送MQTT的数据为" + str);
var request1 = new RestRequest("/", Method.Post);
//注意方法是POST
//两个参数名字必须是 topic 和payload ,区分大小写的
//Console.WriteLine("Topic: " + debug_log_report_mqtt_topic);
request1.AddParameter("topic", debug_log_report_mqtt_topic);
request1.AddParameter("payload", str);
await HttpSend.client1.ExecuteAsync(request1);
Console.WriteLine("当前时间为:" + ti+" Data: "+dataHex);
}
catch (Exception ex)
{
Console.WriteLine("发送MQTT数据出错" + ex.Message);
}
}
}
}