VB.NET webserver gets spammando requests

Asked

Viewed 22 times

1

Hello. I’ve just set up a Vb.net webserver to receive requests that arrive on the localhost. This webserver has the role of redirecting these requests to another address. What happens is that it spams the requests and I can’t make it stop.

Imports System.Net
Imports System.Globalization
Module HttpListener

Sub Main()
    Dim prefixes(0) As String
    prefixes(0) = "http://*:80/"
    ProcessRequests(prefixes)
End Sub

Private Sub ProcessRequests(ByVal prefixes() As String)
    If Not System.Net.HttpListener.IsSupported Then
        Console.WriteLine(
            "Windows XP SP2, Server 2003, or higher is required to " &
            "use the HttpListener class.")
        Exit Sub
    End If

    If prefixes Is Nothing OrElse prefixes.Length = 0 Then
        Throw New ArgumentException("prefixes")
    End If

    Dim listener As System.Net.HttpListener =
        New System.Net.HttpListener()
    For Each s As String In prefixes
        listener.Prefixes.Add(s)
    Next

    Try

        listener.Start()
        Console.WriteLine("Listening...")

        Dim numRequestsToBeHandled As Integer = 10000

        For i As Integer = 0 To numRequestsToBeHandled
            Dim response As HttpListenerResponse = Nothing
            Try

                Dim context As HttpListenerContext = listener.GetContext()

                response = context.Response
                Dim path As String = context.Request.Url.AbsolutePath

            Catch ex As HttpListenerException
                Console.WriteLine(ex.Message)
            Finally
                If response IsNot Nothing Then
                    response.Close()
                End If
            End Try
        Next
    Catch ex As HttpListenerException
        Console.WriteLine(ex.Message)
    Finally

        listener.Close()
        Console.WriteLine("Done Listening...")
    End Try
End Sub
End Module
  • Welcome to Stack Overflow in English. Please click edit and translate the question.

  • Tidy, thank you very much.

No answers

Browser other questions tagged

You are not signed in. Login or sign up in order to post.