C# 飞书webhook
时间: 2023-11-28 08:45:28 浏览: 65
根据提供的引用内容,似乎没有直接关于C#如何发送飞书webhook的信息。不过,我们可以通过C#中的HttpWebRequest类来发送HTTP请求,从而实现发送飞书webhook的功能。以下是一个简单的C#程序示例,可以向飞书机器人发送一条文本消息:
```csharp
using System;
using System.IO;
using System.Net;
using System.Text;
class Program
{
static void Main(string[] args)
{
string webhookUrl = "https://open.feishu.cn/open-apis/bot/v2/hook/XXXX"; // 替换为你的飞书机器人webhook地址
string msgType = "text";
string content = "{\"text\": \"Hello, Feishu!\"}"; // 发送的消息内容,需要进行json编码
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(webhookUrl);
request.Method = "POST";
request.ContentType = "application/json;charset=utf-8";
byte[] data = Encoding.UTF8.GetBytes(content);
request.ContentLength = data.Length;
using (Stream stream = request.GetRequestStream())
{
stream.Write(data, 0, data.Length);
}
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
string responseString = new StreamReader(response.GetResponseStream()).ReadToEnd();
Console.WriteLine(responseString);
}
}
```
需要注意的是,发送的消息需要进行json编码,并且在请求头中指定Content-Type为application/json;charset=utf-8。另外,需要替换代码中的webhookUrl为你自己的飞书机器人webhook地址。