Code: Select all
Dim client As HttpClient
Dim handler As New WebRequestHandler
Dim result As New HttpResponseMessage
Dim CommandString, ResultString As String
Dim CancelTokenSource As New CancellationTokenSource
Dim CancelToken As CancellationToken = CancelTokenSource.Token
CommandString = "http://192.168.1.80/cgi-bin/audio.cgi?action=postAudio&httptype=singlepart&channel=1"
Using handler
handler.Credentials = New NetworkCredential("admin", "password")
client = New HttpClient(handler)
Using client
client.BaseAddress = New Uri(CommandString)
'client.Timeout = TimeSpan.FromMilliseconds(5000)
'client.DefaultRequestHeaders.Add("Content-Type", "Audio/PCM")
'client.DefaultRequestHeaders.Add("Content-Length", bytesRecorded)
client.DefaultRequestHeaders.Add("Connection", "Keep-Alive")
client.DefaultRequestHeaders.Add("Keep-Alive", "3600")
'result = Await client.GetAsync(CommandString, HttpCompletionOption.ResponseContentRead, CancelToken)
Dim byteContent As ByteArrayContent = New ByteArrayContent(buffer)
byteContent.Headers.ContentType = New MediaTypeHeaderValue("Audio/AAC")
byteContent.Headers.ContentLength = bytesRecorded
System.Net.ServicePointManager.Expect100Continue = False
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12
result = Await client.PostAsync(CommandString, byteContent)
'CameraErrorCount = 0
Using result
' result.EnsureSuccessStatusCode()
' ResultString = Await result.Content.ReadAsStringAsync
' If Not ResultString.ToUpper.Contains("OK") Then 'AndAlso Not Action.ToUpper.Contains("STATUS") Then
' Console.WriteLine("ResultString: " & ResultString)
' End If
End Using
End Using
End Using