speeding up the HttpWebRequest POST speed

VBLearner

Newbie
Joined
Sep 19, 2013
Messages
6
Reaction score
0
I have here a working HttpWebRequest code using POST method, but my problem is it is very slow. Sends a request every 1 second interval. Is there any way to speed this up?

Here is my code:

Code:
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click

    Try
        If BackgroundWorker1.IsBusy <> True Then
            BackgroundWorker1.RunWorkerAsync()              
        End If

    Catch ex As Exception

    End Try

End Sub

Private Sub BackgroundWorker1_DoWork(sender As System.Object, e As System.ComponentModel.DoWorkEventArgs) Handles BackgroundWorker1.DoWork

    Dim x As Integer = 0
    Do
        Try
            Dim cweb As String = RichTextBox1.Text
            Dim POST As String = RichTextBox2.Text
            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 = False
            request.ContentType = "application/x-www-form-urlencoded"
            request.ContentLength = POST.Length
            request.Method = "POST"
            request.KeepAlive = False

            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)
            response.Close()

            x += 1
            Label5.Text = x

        Catch ex As Exception
            MessageBox.Show("failed")
        End Try
    Loop While (x < 100)

End Sub

Private Sub BackgroundWorker1_ProgressChanged(sender As System.Object, e As System.ComponentModel.ProgressChangedEventArgs) Handles BackgroundWorker1.ProgressChanged
    Try

    Catch ex As Exception

    End Try
End Sub

Private Sub BackgroundWorker1_Completed(sender As System.Object, e As System.ComponentModel.RunWorkerCompletedEventArgs) Handles BackgroundWorker1.RunWorkerCompleted
    Try
    Catch ex As Exception

    End Try 
End Sub[COLOR=#333333]

[/COLOR]


I want to optimize it's speed similar to a normal loop condition below:

Code:
Dim x As Integer = 0

Do

x+=1

Loop While(x< 100)[COLOR=#333333]
[/COLOR]


Is this possible? Or are there any alternative ways in achieving this? Thanks in advance.
 
Last edited:
is making HttpWebRequest in C++ faster?
I have not tried. But i have spent 2 months for this project already. I don't want to start from scratch.

I was just kidding. I don't use VB and can't help you. But yes, C++ is scores faster in any similar function.
 
The only way to speed things up is to group your requests and don't do one every second. For 1 second it can't connect send the request, receive the response and close. Also you will end up overloading the receiver of the request. Rethink the project and lower/qroup the requests
 
The only way to speed things up is to group your requests and don't do one every second. For 1 second it can't connect send the request, receive the response and close. Also you will end up overloading the receiver of the request. Rethink the project and lower/qroup the requests

Does it mean i have to create multiple instances of requests all at once? I really want to get rid of this delay.
What changes should I have to do with my code?
 
Does it mean i have to create multiple instances of requests all at once? I really want to get rid of this delay.
What changes should I have to do with my code?

no, i meant to combine the data you send in each request into one whole and do just 1 request
 
no, i meant to combine the data you send in each request into one whole and do just 1 request
I won't be able to do that as the purpose of my request is to fill-up a webform and submit it. I need to process the data one by one.
 
well, in that case you need multithreading. Head to google and dig up about VB multithreading, there are tons of examples and code samples about it
 
C++ won't be faster than VB, that's for sure. Speed depends on your internet connection, nothing more. You might want to set timeout.
 
C++ won't be faster than VB, that's for sure. Speed depends on your internet connection, nothing more. You might want to set timeout.

Is there any other way to create webrequests that is not speed dependent on internet connection?
So it will get rid of the delay. My main purpose is to create a spam bot that fills-up a webform and submit it simultaneously.
 
Last edited:
you need to learn about multithreading. it wont speed up the reuqest, but you make 5 requests at once
 
Here is a very simple function using multithreading:

Code:
Private Sub StartThreads()
                For i = 0 To 50
                Dim thread = New Thread(AddressOf test)
                thread.IsBackground = True
                thread.Start()
                Next
         End Sub

That will start 50 threads that are background. Each thread will run the sub or function called test :

Code:
Public Sub Test()
                  MessageBox.show("You just started another thread")
           End Sub

That is the most basic of basic multi-Threading Just make sure to use Thread.isBackground = True If you dont then when you exit your application you will still have threads running. :) well good luck!
 
Is there any other way to create webrequests that is not speed dependent on internet connection?
So it will get rid of the delay. My main purpose is to create a spam bot that fills-up a webform and submit it simultaneously.
There is no way to create web requests that are not depended on your internet speed. If it is taking a second to process each request, then simply add multi-threading as suggested above. There is no other way to get noticeably better results.
 
Here is a very simple function using multithreading:

Code:
Private Sub StartThreads()
                For i = 0 To 50
                Dim thread = New Thread(AddressOf test)
                thread.IsBackground = True
                thread.Start()
                Next
         End Sub

That will start 50 threads that are background. Each thread will run the sub or function called test :

Code:
Public Sub Test()
                  MessageBox.show("You just started another thread")
           End Sub

That is the most basic of basic multi-Threading Just make sure to use Thread.isBackground = True If you dont then when you exit your application you will still have threads running. :) well good luck!

This is very simple and can cause a lot of I/O error ;)
 
Back
Top