intes2010 0 Newbie Poster

I have here a working HTTP request using SOCKETS but I do not know how to send POST requests.

Here is my code:

 Dim hostName As String
            Dim hostPort As Integer
            Dim response As Integer
            Dim iphe As IPHostEntry = Dns.GetHostEntry("")
            hostName = iphe.AddressList(0).ToString()
            hostPort = 80
            response = 0

            Dim host As IPAddress = IPAddress.Parse(hostName)
            Dim hostep As New IPEndPoint(host, hostPort)
            Dim sock As New Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp)

            Dim request = "GET /nationwide/mip/choice-hotels-international-462092189/send_email?lid=161004592 HTTP/1.1" & vbCr & vbLf &
                          "Host:" & vbCr & vbLf &
                          "User-Agent: Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36" & vbCr & vbLf &
                          "Connection: keep-alive" & vbCr & vbLf &
                          "Content-Type: application/x-www-form-urlencoded" & vbCr & vbLf &
                          "Content-Length: 0" & vbCr & vbLf & vbCr & vbLf

            response = sock.Send(Encoding.UTF8.GetBytes(request))
            response = sock.Send(Encoding.UTF8.GetBytes(vbCr & vbLf))


I wanted to fill-up this webform i have mentioned in my code with these data: Name&

How do I do it? I have successfully done this using HttpWebRequest using the code below:

Dim cweb As String = ""
        Dim POST As String = "& Name& There"       

        Dim request As HttpWebRequest
        Dim response As HttpWebResponse

        request = CType(WebRequest.Create(cweb), HttpWebRequest)
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/28.0.1500.72 Safari/537.36"
        request.AllowAutoRedirect = True
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = POST.Length
        request.Method = "POST"
        request.KeepAlive = True

        Dim requestStream As Stream = request.GetRequestStream()
        Dim postBytes As Byte() = Encoding.ASCII.GetBytes(POST)
        requestStream.Write(postBytes, 0, postBytes.Length)

        response = CType(request.GetResponse(), HttpWebResponse)

But I wanted to recreate this concept by the use of SOCKETS.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts learning and sharing knowledge.