Hi,
I'm trying to get a project up and running, but am not having much luck and could use some help. I'm wondering how I can connect to it and send it GET requests and read the response. I'm receiving error messages that say the Response Name is invalid.
Here's what's happening. The server is connected to a microprocessor and it communicates with my PC via ethernet cable via a router over my local network. I call the IP address of the server+micro (http://192.168.0.5/) and on the end can add "s" for status update, "t" + a number (0 to 7) to toggle LED's connected to the micro. When just the IP address is sent the response should be a standard HTTP response and an ASCII string "Connected". When I use the IP address and either "s" or "t"(+ a number) the response is again a standard HTTP response header and in the response body is ASCII string "var AN0= xxx;var PortB= xxx;var PortD= xxx;".
Using WireShark I can see that this is exactly what happens, even though my Windows Forms App stops and states the error mentioned above that "The server committed a protocol violation. Section=ResponseHeader Detail=Header name is invalid".
I'm trying a few different ways to write the code for the forms app. I've tried HttpWebRequest, WebRequest and Socket Class.
The first two I can get the LED I want to toggle, but from there the debugger stops and shows me the webrequest exception.
I'm stuck, help please....
Here's what I'm doing, I have adapted this from a help file found online. It's just a small section.
Any ideas?
Chris
I'm trying to get a project up and running, but am not having much luck and could use some help. I'm wondering how I can connect to it and send it GET requests and read the response. I'm receiving error messages that say the Response Name is invalid.
Here's what's happening. The server is connected to a microprocessor and it communicates with my PC via ethernet cable via a router over my local network. I call the IP address of the server+micro (http://192.168.0.5/) and on the end can add "s" for status update, "t" + a number (0 to 7) to toggle LED's connected to the micro. When just the IP address is sent the response should be a standard HTTP response and an ASCII string "Connected". When I use the IP address and either "s" or "t"(+ a number) the response is again a standard HTTP response header and in the response body is ASCII string "var AN0= xxx;var PortB= xxx;var PortD= xxx;".
Using WireShark I can see that this is exactly what happens, even though my Windows Forms App stops and states the error mentioned above that "The server committed a protocol violation. Section=ResponseHeader Detail=Header name is invalid".
I'm trying a few different ways to write the code for the forms app. I've tried HttpWebRequest, WebRequest and Socket Class.
The first two I can get the LED I want to toggle, but from there the debugger stops and shows me the webrequest exception.
I'm stuck, help please....
Here's what I'm doing, I have adapted this from a help file found online. It's just a small section.
Code:
Private Sub BtnToggle_Click(sender As System.Object, e As System.EventArgs) Handles BtnToggle.Click
Dim Client As WebClient = New WebClient()
'Send request to toggle LED
Dim Data As Stream = Client.OpenRead("http://" & TextBoxIP.Text.Trim & "/t" & TextBoxPin.Text.Trim)
'Read the response, (status) from PIC
Dim Reader As StreamReader = New StreamReader(Data) 'Here's where the code stops
Dim Str As String = ""
Str = Reader.ReadLine()
Do While Str.Length > 0
'Display result is some temporary text box
TextBoxResults.Text = Str
Str = Reader.ReadLine()
Loop
End Sub
Chris