Hi all
I am just experimenting with HttpWebRequest as I want to interface with a micro controller on my network that has its own inbuilt web page.
It has a page where I have to input a password and then press a button to change an output on the controller board.
when i use it, it works and the output state is changed but when i use this code more than once or twice my whole program locks up and i have to stop it in the IDE.
could someone have a look at my code for me please ?
I have never done this before and feel maybe I should close the connection after each use? but i don't understand how to.
I am using this code.
Public Sub TurnOn()
' Put a "/" character at the end of the URL if it doesn't exist
Try
If Not txtUrl.EndsWith("/") Then
txtUrl += "/"
End If
Dim strOn As String = "sc=1&"
' tm = Timeout value in minutes, 0 = no timeout
Dim strTm As String =[String].Format("tm={0}&", 0)
' Pw = password
Dim strPw As String = [String].Format("pw={0}", txtPassword)
Dim webRequest__1 As HttpWebRequest = DirectCast(WebRequest.Create((txtUrl & "?") + strOn + strTm + strPw), HttpWebRequest)
webRequest__1.Method = "GET"
Dim response As HttpWebResponse = DirectCast(webRequest__1.GetResponse(), HttpWebResponse)
Catch ex As Exception
Stop
End Try
End Sub
I am just experimenting with HttpWebRequest as I want to interface with a micro controller on my network that has its own inbuilt web page.
It has a page where I have to input a password and then press a button to change an output on the controller board.
when i use it, it works and the output state is changed but when i use this code more than once or twice my whole program locks up and i have to stop it in the IDE.
could someone have a look at my code for me please ?
I have never done this before and feel maybe I should close the connection after each use? but i don't understand how to.
I am using this code.
Public Sub TurnOn()
' Put a "/" character at the end of the URL if it doesn't exist
Try
If Not txtUrl.EndsWith("/") Then
txtUrl += "/"
End If
Dim strOn As String = "sc=1&"
' tm = Timeout value in minutes, 0 = no timeout
Dim strTm As String =[String].Format("tm={0}&", 0)
' Pw = password
Dim strPw As String = [String].Format("pw={0}", txtPassword)
Dim webRequest__1 As HttpWebRequest = DirectCast(WebRequest.Create((txtUrl & "?") + strOn + strTm + strPw), HttpWebRequest)
webRequest__1.Method = "GET"
Dim response As HttpWebResponse = DirectCast(webRequest__1.GetResponse(), HttpWebResponse)
Catch ex As Exception
Stop
End Try
End Sub