Is it possible to make a web request using sockets? I am still studying about socket programming in VB.net and i wanted to upgrade my web request code using sockets.

Here is my web request code:

    Dim cweb As String = "http://www.samplewebsite.com/"
    Dim POST As String = "sample post data"
    Dim request As HttpWebRequest
    Dim response As HttpWebResponse
    Dim tempCookies As New CookieContainer

        request = CType(WebRequest.Create(cweb), HttpWebRequest)
        request.UserAgent = "Mozilla/5.0 (Windows NT 6.1; WOW64; rv:23.0) Gecko/20100101 Firefox/23.0"
        request.AllowAutoRedirect = True
        request.ContentType = "application/x-www-form-urlencoded"
        request.ContentLength = POST.Length
        request.Method = "POST"
        request.KeepAlive = True
        request.CookieContainer = tempCookies


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

        response = CType(request.GetResponse(), HttpWebResponse)
        tempCookies.Add(response.Cookies)
        Dim postreader As New StreamReader(response.GetResponseStream())
        Dim thepage As String = postreader.ReadToEnd
        response.Close()

Any samples or tips will be gladly accepted i really want to learn making a web request using sockets. Thanks in advance.

Recommended Answers

All 2 Replies

Here is a forum post in StackOverflow when a user posted information on this very subject!

I hope it helps!

yes I have seen that but i have no idea on how to make a post request method using sockets

Be a part of the DaniWeb community

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