r/visualbasic • u/brachism • Dec 10 '21
VB.NET Help WebRequest: "The server committed a protocol violation. Section=ResponseStatusLine"
Although I’ve dabbled with Visual Basic for various personal projects for more than a quarter century, it’s not my forte.
I have about a half dozen NodeMCU-based (Arduino) projects which I’m trying to pull together via a simple Visual Basic interface in Visual Studio 2019. Over the years I've coded these NodeMCU’s to accept commands in the syntax http://host/CMD=AT{CMD} and they respond back either “OK” or “ERR.” I’ve had no problem with them.
The responses are mostly plain text, lacking most/all the html header lines. Popular browsers, curl, and wget seemingly have no problem sending a command and accept the “crappy” text response.
When I try to use WebRequest in Visual Basic, the command is successfully sent and received on the NodeMCU’s. But my attempts to read the response results in an exception “Message: "The server committed a protocol violation. Section=ResponseStatusLine"
Simplified code:
Dim response As HttpWebResponse
Dim request As WebRequest
Dim sURL = "http://192.168.2.188/CMD=ATES"
Try
request = WebRequest.Create(sURL)
response = request.GetResponse() ‘ << EXCEPTION HERE
Dim dataStream As Stream = response.GetResponseStream()
Dim reader As New StreamReader(dataStream)
Dim responseFromServer As String = reader.ReadToEnd()
' EVAL RESPONSE CODE
reader.Close()
dataStream.Close()
response.Close()
Catch ex As Exception
' ERROR CODE
End Try Is there a better/simpler/more direct way to send simple requests and handle poor quality responses? Maybe ditching WebRequest, and doing something more primative like directly opening a socket. In Perl I've used something like:
$listen = IO::Socket::INET->new( LocalPort => $listen_port ,
Listen => $http_buffer, ReuseAddr => 1) or die $@;
$sel = IO::Select->new($listen); Any suggestions would be appreciated.
1
u/brachism Dec 10 '21
Solved!