Public Sub sendLine(txt As String)
Chart1.SaveImage(My.Application.Info.DirectoryPath & "\charts\T201.jpeg", System.Drawing.Imaging.ImageFormat.Jpeg)
'txt & vbCrLf & "วันที่ - เวลา : " & FormatDateTime(Now(), DateFormat.GeneralDate)
Try
Dim LineMessage As String = String.Format("message={0}", txt)
Dim pictureUrl As String = My.Application.Info.DirectoryPath & "\charts\T201.jpeg"
System.Net.ServicePointManager.Expect100Continue = False
Dim Request = CType(WebRequest.Create("https://notify-api.line.me/api/notify"), HttpWebRequest)
Dim imageFile = String.Format("imageFile={0}", pictureUrl)
LineMessage += "&" + imageFile.ToString()
'// Message to Line
Dim MyData = Encoding.UTF8.GetBytes(LineMessage)
'//
Request.Method = "POST"
'// Initialize
With Request
.ContentType = "application/x-www-form-urlencoded"
.ContentLength = MyData.Length
'// Change your Token and don't cut "Bearer".
.Headers.Add("Authorization", "Bearer XXXXXXXX")
.AllowWriteStreamBuffering = True
.KeepAlive = False
.Credentials = CredentialCache.DefaultCredentials
End With
'//
Using Stream = Request.GetRequestStream()
Stream.Write(MyData, 0, MyData.Length)
End Using
Dim response = DirectCast(Request.GetResponse(), HttpWebResponse)
Dim responseString = New StreamReader(response.GetResponseStream()).ReadToEnd()
Catch ex As Exception
MessageBox.Show(ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Error)
End Try
End Sub
Tag : .NET, Win (Windows App), VB.NET, VS 2017 (.NET 4.x), Windows
'เรียกใช้งาน
Dim arg As String
arg = " -X POST -H ""Authorization: Bearer FY51f34qLnSGVcdfsfsfsdfsdfsdfs"" -F ""message=TEST"" -F ""imageFile=@D:\Test.png"" https://notify-api.line.me/api/notify"
ShellandWait("curl.exe", arg)
Public Sub ShellandWait(ByVal ProcessPath As String, ByVal Arguments As String)
Dim objProcess As System.Diagnostics.Process
Try
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.Arguments = Arguments
'objProcess.StartInfo.StandardOutputEncoding = Encoding.UTF8
'objProcess.StartInfo.StandardErrorEncoding = Encoding.UTF8
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
objProcess.Start()
'Wait until it's finished
Application.DoEvents()
objProcess.WaitForExit()
Application.DoEvents()
'Exitcode as String
Console.WriteLine(objProcess.ExitCode.ToString())
objProcess.Close()
Catch ex As Exception
Console.WriteLine("Could not start process " & ProcessPath & " " & ex.Message.ToString)
End Try
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim arg As String
arg = " -X POST -H ""Authorization: Bearer <LINE TOKEN HERE>"" -F ""message=TEST"" -F ""imageFile=@C:\charts\PIC.png"" https://notify-api.line.me/api/notify"
ShellandWait("curl.exe", arg)
End Sub
Public Sub ShellandWait(ByVal ProcessPath As String, ByVal Arguments As String)
Dim objProcess As System.Diagnostics.Process
Try
objProcess = New System.Diagnostics.Process()
objProcess.StartInfo.Arguments = Arguments
objProcess.StartInfo.FileName = ProcessPath
objProcess.StartInfo.WindowStyle = ProcessWindowStyle.Hidden
objProcess.Start()
Application.DoEvents()
objProcess.WaitForExit()
Application.DoEvents()
Console.WriteLine(objProcess.ExitCode.ToString())
objProcess.Close()
Catch ex As Exception
MsgBox("Could not start process " & ProcessPath & " " & ex.Message.ToString)
End Try
End Sub
ประวัติการแก้ไข 2019-01-25 09:29:36
Date :
2019-01-25 09:29:09
By :
realizejoke
No. 20
Guest
รบกวนผู้รู้ด้วยนะคะ ไม่รู้จะทำยังไง ให้สามารถ ส่งข้อความจากเครื่องไปที่ line ได้