1,105,386 Community Members

HttpWebRequest with Sockets

Member Avatar
intes2010
Newbie Poster
9 posts since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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.

Member Avatar
Begginnerdev
Veteran Poster
1,141 posts since Apr 2010
Reputation Points: 251 [?]
Q&As Helped to Solve: 191 [?]
Skill Endorsements: 15 [?]
 
0
 

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

I hope it helps!

Member Avatar
intes2010
Newbie Poster
9 posts since Jul 2013
Reputation Points: 0 [?]
Q&As Helped to Solve: 0 [?]
Skill Endorsements: 0 [?]
 
0
 

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

You
This article has been dead for over three months: Start a new discussion instead
Post:
Start New Discussion
Tags Related to this Article