I'm trying to post to an ASP.NET Site via Sockets by sending the Raw HTTP Request information however; when trying to read the response I get
"Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host."
Here is the code I am using
Public Function PerformGetRequest() As String
Dim strResponse As String = String.Empty
Dim GetRequest As New System.Text.StringBuilder
Dim lStreamWriter As StreamWriter = Nothing
Dim lStreamReader As StreamReader = Nothing
Dim lNetworkStream As NetworkStream = Nothing
GetRequest.Append(String.Format("GET http://{0}/default.aspx HTTP/1.1{1}", mstrHost, vbCrLf))
GetRequest.Append(My.Settings.HTTPAcceptString & vbCrLf)
GetRequest.Append(My.Settings.HTTPAcceptLanguageString & vbCrLf)
GetRequest.Append(My.Settings.HTTPUserAgentString & vbCrLf)
GetRequest.Append(My.Settings.HTTPEncodingString & vbCrLf)
GetRequest.Append(My.Settings.HTTPConnectionString & vbCrLf)
GetRequest.Append(String.Format(My.Settings.HTTPHostString, mstrHost & vbCrLf))
Try
If Not mTcpClient.Connected Then
mTcpClient.Connect(mstrHost, 80)
End If
If Not mSocket.Connected Then
mSocket.Connect(mstrHost, 80)
End If
lNetworkStream = mTcpClient.GetStream()
lStreamReader = New StreamReader(lNetworkStream, True)
lStreamWriter = New StreamWriter(lNetworkStream)
lStreamWriter.WriteLine(GetRequest.ToString)
lStreamWriter.Flush()
strResponse=lStreamReader.ReadToEnd()
Catch ex As Exception
Throw New Exception(ex.Message)
End Try
Return strResponse
End Function
The exception occurs at the lStreamReader.ReadToEnd line.
Thanks in advance for any assistance.