Tornado.Send\Program.cs
new TornadoSend().SendContentFromFive("这是测试消息");
Tornado.Send\Tornado.cs
using System.Net;
using System.Text;
public class TornadoSend
{
private readonly string url5g = "";
private readonly Dictionary<string, string> data = new()
{
{ "userID", "xxx" },
{ "jobCat", "xxx" },
{ "scene", "xxx" },
{ "tag", "xxx" },
{ "param", "" }
};
private readonly Dictionary<string, string> header = new()
{
{ "Content-Type", "application/x-www-form-urlencoded;charset=UTF-8" },
};
public bool SendContentFromFive(string content)
{
data.Add("desc", content);
#pragma warning disable SYSLIB0014 // Type or member is obsolete
var request = (HttpWebRequest)WebRequest.Create(url5g);
#pragma warning restore SYSLIB0014 // Type or member is obsolete
request.Method = "POST";
foreach (var item in header)
{
request.Headers.Add(item.Key, item.Value);
}
var postData = GetPostData(data);
request.ContentLength = postData.Length;
using (var stream = request.GetRequestStream())
{
stream.Write(postData, 0, postData.Length);
}
try
{
var response = (HttpWebResponse)request.GetResponse();
var res = GetResponseContent(response);
if (res != "0000")
{
Console.WriteLine("龙卷风发送失败-->");
Console.WriteLine(res);
return false;
}
Console.WriteLine("龙卷风发送成功!!!");
return true;
}
catch (Exception e)
{
Console.WriteLine(e.Message);
return false;
}
}
private static byte[] GetPostData(Dictionary<string, string> data)
{
var sb = new StringBuilder();
foreach (var item in data)
{
sb.Append($"{item.Key}={item.Value}&");
}
return Encoding.UTF8.GetBytes(sb.ToString().TrimEnd('&'));
}
private static string GetResponseContent(HttpWebResponse response)
{
using (var stream = response.GetResponseStream())
{
using (var reader = new StreamReader(stream))
{
return reader.ReadToEnd();
}
}
}
}