c# Line Notify 範例
今天來練習一下line通知功能,步驟如下:
- 到https://notify-bot.line.me/my/註冊
- 取得"發行存取權杖",並輸入你的名字和發通知的群組(畫面如下)
- 取得token
- 撰寫相關程式(畫面如下)
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://notify-api.line.me/api/notify");
request.Method = "POST";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = byteArray.Length;
request.Headers.Add("Authorization", "Bearer " + token);
request.AutomaticDecompression = DecompressionMethods.GZip;
request.ClientCertificates.Add(new System.Security.Cryptography.X509Certificates.X509Certificate());
Stream dataStream = request.GetRequestStream();
dataStream.Write(byteArray, 0, byteArray.Length);
HttpWebResponse resp = (HttpWebResponse)request.GetResponse();
using (StreamReader str = new StreamReader(resp.GetResponseStream()))
{
string responseFromServer = str.ReadToEnd();
responseFromServer.Contains("ok");
str.Close();
}
參考文獻:
https://sites.google.com/view/squarecat/line-%E9%96%8B%E7%99%BC/c-line-notify?pli=1
留言
張貼留言