Search code examples
vb.netsystem.net.httpwebrequest

Anonymous HTTP Web Request


I created http request application to test my web site qulatiy (see below).

 Dim Request As HttpWebRequest = WebRequest.Create(webAddress)
 Dim Response As HttpWebResponse = Request.GetResponse()

 Request.Method = "Get"

 Dim Reader As New StreamReader(Response.GetResponseStream)
 Dim Html As String = Reader.ReadToEnd()

In this case, I would like to create anonymous request without catching the response. How can I do that?


Solution

  • To do so, u have to get a little low level , working with sockets

    TcpCient in this case

    Sample code

    Imports System.Net.Sockets
    
    
    Module Module1
    
        Sub Main()
    
            Dim tcpcli = New TcpClient()
            tcpcli.Connect("google.co.in", 80)
    
            Dim stream As NetworkStream = tcpcli.GetStream()
            Dim reqdata As String = String.Format("GET / HTTP/1.1{0}Host: www.google.co.in{0}Connection: Close{0}{0}", vbCrLf)
            Dim reqbytes() As Byte = Text.Encoding.ASCII.GetBytes(reqdata)
    
            stream.Write(reqbytes, 0, reqbytes.Length)
    
            stream.Close()
            stream.Dispose()
    
            tcpcli.Close()
    
    
    
        End Sub
    
    End Module
    

    Network capture via wireshark (no response received) no response receive as no response was read from socket