所以我有一个包含我想要的信息(日期、固件版本等)的 IP 摄像机,并且通过从 http URL 转到 Http.GetResponse() 并获取 XML 响应字符串来获取每条信息。例如,"http://" & ip & "/System/Audio/Channels" 给你一个关于它的音频通道的字符串。
我需要很多信息,但该设备没有列出我需要的所有项目的 URL,因此我对每个设备重复此过程,其中包含 x 个项目特定 URL。以下是仅使用一个 URL 的代码片段:
Dim RespStr As String = "http://" & ip & "/System/Audio/Channels"
'Open Request...
Dim HttpReq As Net.HttpWebRequest = Nothing
Try
'create request object
HttpReq = CType(Net.WebRequest.Create(ReqStr), Net.HttpWebRequest)
'set the username and password
HttpReq.Credentials = New Net.NetworkCredential(camera.Username, camera.Password)
'set method
HttpReq.Method = "GET"
'disable expect-100-continue
HttpReq.ServicePoint.Expect100Continue = False
'timeout
HttpReq.Timeout = 1000 * 2
Catch ex As Exception
End Try
'Open Response...
Dim HttpResp As Net.HttpWebResponse = Nothing
Dim HttpStatus As Net.HttpStatusCode = Nothing
Try
'get the response
HttpResp = CType(HttpReq.GetResponse(), Net.HttpWebResponse)
'verify the response
HttpStatus = HttpResp.StatusCode
If HttpStatus <> Net.HttpStatusCode.OK Then
'error
End If
'do stuff to process xml string
Catch ex As Exception
End Try
显然,在特定 URL 循环第 10 次之后,您开始变得缓慢和重复。
有没有办法以更快的方式告诉 vb.net 转到 url1、url2、url3(都类似于我上面提到的示例)并在一次网络尝试中连接所有字符串响应?甚至可能一次,因为它是相同的 IP 地址?然后我可以在我的一端而不是通过网络来处理它。