close

根據line 所提供的API 文件

https://notify-bot.line.me/doc/en/

image

image

試了幾天終於成功了

1.準備圖檔

網路上擷取的圖片存於D:\

imageimage

2.

using System.Net.Http;   //Call API
using System.IO;             //讀檔

3
        private void button2_Click(object sender, EventArgs e)
        {
            try
            { 
            var file = @"D:\2324.jpg";                                         //圖檔位置
            var upfilebytes = File.ReadAllBytes(file);
            HttpClientHandler handler = new HttpClientHandler();
            HttpClient Client = new HttpClient(handler);
            Client.DefaultRequestHeaders.Authorization = new System.Net.Http.Headers.AuthenticationHeaderValue("Bearer", "mxbYX3GTvB1H");    //Token
            MultipartFormDataContent content = new MultipartFormDataContent();          
            ByteArrayContent baContent = new ByteArrayContent(upfilebytes);             
            content.Add(baContent, "imageFile", "2324.jpg");
            string url = @"https://notify-api.line.me/api/notify?message=";         //組訊息
             url = url + textBox1.Text.ToString();
            var response =Client.PostAsync(url, content).Result;
            }
            catch(Exception ex)
            {

            }
        }

4.測試

image

image

 

 

arrow
arrow
    文章標籤
    c# linenotify line
    全站熱搜

    JosephChou 發表在 痞客邦 留言(1) 人氣()