Dim handler = New HttpClientHandler()
handler.UseCookies = False
Using httpClient = New HttpClient(handler)
Using request = New HttpRequestMessage(New HttpMethod("GET"), "http://192.168.1.35/FileBrowser/Download?Path=/DataLogs/DOSAGGIO.csv")
request.Headers.TryAddWithoutValidation("Referer", "http://192.168.1.35/Portal/Portal.mwsl?PriNav=FileBrowser&Path=/DataLogs")
request.Headers.TryAddWithoutValidation("Cookie", "cookie.txt")
Dim response = Await httpClient.SendAsync(request)
result = Await response.Content.ReadAsStringAsync()
If result IsNot Nothing And result.Length > 0 Then
Debug.WriteLine(result.Substring(0, 100))
End If
' TextBox2.Text = result
' DataGridView1.DataSource = result
'TextBox1.Text = result.Substring(0, 100)
End Using
End Using
'lettura
Dim tr = New MemoryStream(Encoding.UTF8.GetBytes(result))
Dim sw = New StreamReader(tr)
ProgressBar1.Value = 0
ProgressBar1.Maximum = 1001
Dim CONTA = 1000
For I = 0 To CONTA
If sw.Peek() <> -1 Then
Dim Str2() As String = Split(sw.ReadLine(), ",")
If I < 1 Then
For T = 0 To 7 '9
DataGridView1.Columns(T).HeaderText = Str2(T)
Next T
Else
'DataGridView1.Rows.Add(Str2(0), Str2(1), Str2(2), Str2(3), Str2(4), Str2(5), Str2(6), Str2(7), Str2(8), Str2(9)) '
DataGridView1.Rows.Add(Str2(0), Str2(1), Str2(2), Str2(3), Str2(4), Str2(5), Str2(6), Str2(7))
End If
Else
End If
ProgressBar1.Value += 1
Next I
sw.Close()
'FILE SALVA OK
Dim path As String = My.Application.Info.DirectoryPath
Dim memString As String = result
' convert string to stream
Dim buffer As Byte() = Encoding.ASCII.GetBytes(memString)
Dim ms As New MemoryStream(buffer)
'write to file
Dim file As New FileStream(path & "\DOSAGE.csv", FileMode.Create, FileAccess.Write)
ms.WriteTo(file)
file.Close()
ms.Close()
handler.UseCookies = False
Using httpClient = New HttpClient(handler)
Using request = New HttpRequestMessage(New HttpMethod("GET"), "http://192.168.1.35/FileBrowser/Download?Path=/DataLogs/DOSAGGIO.csv")
request.Headers.TryAddWithoutValidation("Referer", "http://192.168.1.35/Portal/Portal.mwsl?PriNav=FileBrowser&Path=/DataLogs")
request.Headers.TryAddWithoutValidation("Cookie", "cookie.txt")
Dim response = Await httpClient.SendAsync(request)
result = Await response.Content.ReadAsStringAsync()
If result IsNot Nothing And result.Length > 0 Then
Debug.WriteLine(result.Substring(0, 100))
End If
' TextBox2.Text = result
' DataGridView1.DataSource = result
'TextBox1.Text = result.Substring(0, 100)
End Using
End Using
'lettura
Dim tr = New MemoryStream(Encoding.UTF8.GetBytes(result))
Dim sw = New StreamReader(tr)
ProgressBar1.Value = 0
ProgressBar1.Maximum = 1001
Dim CONTA = 1000
For I = 0 To CONTA
If sw.Peek() <> -1 Then
Dim Str2() As String = Split(sw.ReadLine(), ",")
If I < 1 Then
For T = 0 To 7 '9
DataGridView1.Columns(T).HeaderText = Str2(T)
Next T
Else
'DataGridView1.Rows.Add(Str2(0), Str2(1), Str2(2), Str2(3), Str2(4), Str2(5), Str2(6), Str2(7), Str2(8), Str2(9)) '
DataGridView1.Rows.Add(Str2(0), Str2(1), Str2(2), Str2(3), Str2(4), Str2(5), Str2(6), Str2(7))
End If
Else
End If
ProgressBar1.Value += 1
Next I
sw.Close()
'FILE SALVA OK
Dim path As String = My.Application.Info.DirectoryPath
Dim memString As String = result
' convert string to stream
Dim buffer As Byte() = Encoding.ASCII.GetBytes(memString)
Dim ms As New MemoryStream(buffer)
'write to file
Dim file As New FileStream(path & "\DOSAGE.csv", FileMode.Create, FileAccess.Write)
ms.WriteTo(file)
file.Close()
ms.Close()