Dirk Jansen

Dirk Jansen

  • NA
  • 1
  • 4.7k

Check username & password trough httpwebrequest (Basic Authorisation)

Nov 27 2010 2:52 PM
Hello Everyone,

I'm trying to create a code wich checks the username & password on the website he has entered:
This is my code so far:

   Try
            Dim request As WebRequest = _
            WebRequest.Create(TextBox3.Text)
            request.Credentials = New NetworkCredential(TextBox1.Text, TextBox2.Text)
            Dim myHttpWebResponse As HttpWebResponse = CType(request.GetResponse(), HttpWebResponse)

            If myHttpWebResponse.StatusCode = HttpStatusCode.OK Then
                MsgBox("OK")
            Else
                MsgBox("Errror")
            End If

        Catch e As WebException
            Console.WriteLine(ControlChars.Lf + ControlChars.NewLine + "Exception Raised. The following error occured : {0}", e.Status)
        Catch e As Exception
            Console.WriteLine(ControlChars.NewLine + "The following exception was raised : {0}", e.Message)
        End Try

Everything works fine when i enter a working username & password. But when i enter an invalid username & password
nothing happends. How can i solve this?

Or even better, can i get the status code in a string (Like 200 or 401)
Thanks