我想知道如何将proxy username and proxy password
添加到Form1
以便能够在Windows全局设置中更改我的代理。
目前可以使用,但仅格式Proxy IP : Proxy port
我的代理提供商只给了我代理
Imports System.IO
Imports System.Net
Public Class Form1
Private Sub btnconnect_Click(sender As Object, e As EventArgs) Handles btnConnectDisconnect.Click
Dim clsProxy As New IEProxy
If My.Settings.IEProxyConnected Then
If clsProxy.DisableProxy Then
btnConnectDisconnect.Text = "Connect"
My.Settings.IEProxyConnected = False
MessageBox.Show("Proxy successfully disabled.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Error disabling proxy.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
Else
If Not (String.IsNullOrEmpty(txtIP.Text) Or String.IsNullOrEmpty(txtPort.Text)) Then
Dim port As Integer
Dim proxyIP_user As String = txtUser.Text
Dim proxyIP_pass As String = txtPass.Text
If Integer.TryParse(txtPort.Text, port) Then
Dim p As WebProxy = New WebProxy(txtIP.Text.Trim, port)
Dim credentials As ICredentials = New NetworkCredential(proxyIP_user, proxyIP_pass)
My.Settings.RootProxy = p
My.Settings.Save()
Dim x As WebProxy = New WebProxy(txtIP.Text, True, Nothing, credentials)
If clsProxy.SetProxy(p.Address.Host & ":" & p.Address.Port) Then
btnConnectDisconnect.Text = "Disconnect"
My.Settings.IEProxyConnected = True
MessageBox.Show("Proxy successfully enabled.", "Success", MessageBoxButtons.OK, MessageBoxIcon.Information)
Else
MessageBox.Show("Error enabling proxy.", "Failed", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
Else
MessageBox.Show("Please enter the proxy bought from StormProxy.com", "Error", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
End If
End If
My.Settings.Save()
End Sub
End Class