我正在尝试向Snom PA1铃声发送网络请求。铃声在一天中定期响起,但偶尔也会试图接触铃声。这样会很好,但是在这种情况发生几次之后,Web请求就会完全停止发送。子仍然运行,但没有响铃。此外,在调试时,webrequest会抛出一个未被catch处理的webexception,即使它包含在try / catch中。
有人知道为什么网页请求会在失败后停止工作吗?
Private Sub ringIPBell(ByVal params() As Object, Optional ByVal secondattempt As Boolean = False)
Dim IPaddress As String = params(0)
Dim ringSeconds As Double = params(1)
Dim wr As Net.HttpWebRequest
If ringSeconds = 2 Then
wr = Net.HttpWebRequest.Create("http://" & IPaddress & "/line_login.htm?l=2")
Else
wr = Net.HttpWebRequest.Create("http://" & IPaddress & "/line_login.htm?l=1")
End If
wr.Method = "post"
wr.CachePolicy = New System.Net.Cache.RequestCachePolicy(System.Net.Cache.RequestCacheLevel.NoCacheNoStore) 'added Oct2010
wr.Credentials = New Net.NetworkCredential("correctName", "correctPassword")
Dim postdata As String = "PLAY_RINGER:1=Play Ringer"
wr.ContentLength = postdata.Length + 2
Dim requestStream As IO.Stream, strmwrit As IO.StreamWriter
Try
requestStream = wr.GetRequestStream()
strmwrit = New IO.StreamWriter(requestStream)
strmwrit.WriteLine(postdata)
strmwrit.Close()
Dim responsestream As New IO.StreamReader(wr.GetResponse.GetResponseStream)
Catch ex As System.Net.WebException
If Not secondattempt Then
ringIPBell(params, True)
End If
Dim testvar As String = ex.ToString
Catch ex As Exception
Beep()
End Try
此外,我之前有以下代码响铃,但它只适用于两个铃声之一,即使我可以告诉他们的设置是相同的。
requestStream = wr.GetRequestStream()
strmwrit = New IO.StreamWriter(requestStream)
strmwrit.WriteLine(postdata)
strmwrit.Close()
requestStream.Close()
正如我所说,我打破了responestream系列:
requestStream = wr.GetRequestStream()
strmwrit = New IO.StreamWriter(requestStream)
strmwrit.WriteLine(postdata)
strmwrit.Close()
它打破" requestStream = wr.GetRequestStream()"
错误:
"类型' System.Net.WebException'的第一次机会异常发生在System.dll中 附加信息:操作已超时"