Imports System.IO
Imports ComponentPro.Net

Partial Public Class _Default
	Inherits System.Web.UI.Page
	Protected Sub Page_Load(ByVal sender As Object, ByVal e As EventArgs)

	End Sub

	''' <summary>
	''' Handles the Send button's Click event.
	''' </summary>
	''' <param name="sender">The button object.</param>
	''' <param name="e">The event arguments.</param>
	Protected Sub btn_Click(ByVal sender As Object, ByVal e As EventArgs)
		Try
			' Construct request message to send to the destination host.
			Dim requestMessage As String = "GET / HTTP/1.0" & vbCrLf & "Host: " & txtHostName.Text & vbCrLf & "Connection: close" & vbCrLf & vbCrLf

			Dim proxyPort As Integer
			If txtProxyPort.Text.Trim().Length = 0 Then
				proxyPort = 1080
			Else
				proxyPort = Integer.Parse(txtProxyPort.Text)
			End If

			' Create a new instance of the ProxyClient and connect to the host address.
			Using proxyClient As ProxyClient = New ProxyClient(txtHostName.Text, Integer.Parse(txtPort.Text), CType(ddlProxyType.SelectedIndex, ProxyType),IIf(ddlMethod.SelectedIndex = 0, ProxyHttpConnectAuthMethod.Basic, ProxyHttpConnectAuthMethod.Ntlm), txtProxyServer.Text, proxyPort, txtUserName.Text, txtPassword.Text, txtDomain.Text)
				' Send the request message.
				Dim streamWriter As New StreamWriter(proxyClient.GetStream())
				streamWriter.Write(requestMessage)
				streamWriter.Flush()

				' And read response.
				Dim streamReader As New StreamReader(proxyClient.GetStream())
				txtOutput.Text = streamReader.ReadToEnd()
			End Using
		Catch exc As Exception
			' Show error.
			txtOutput.Text = String.Format(Nothing, "Exception: {0}", exc.Message)
		End Try
	End Sub
End Class