我有一段可以在webbrowser中设置代理(ip:port)的代码,是否可以通过VB.net以编程方式在Firefox或Chrome中设置代理?
<Runtime.InteropServices.DllImport("wininet.dll", SetLastError:=True)> _
Private Shared Function InternetSetOption(ByVal hInternet As IntPtr, ByVal dwOption As Integer, ByVal lpBuffer As IntPtr, ByVal lpdwBufferLength As Integer) As Boolean
End Function
Public Structure Struct_INTERNET_PROXY_INFO
Public dwAccessType As Integer
Public proxy As IntPtr
Public proxyBypass As IntPtr
End Structure
Private Sub RefreshIESettings(ByVal strProxy As String)
Const INTERNET_OPTION_PROXY As Integer = 38
Const INTERNET_OPEN_TYPE_PROXY As Integer = 3
Dim struct_IPI As Struct_INTERNET_PROXY_INFO
' Filling in structure
struct_IPI.dwAccessType = INTERNET_OPEN_TYPE_PROXY
struct_IPI.proxy = Marshal.StringToHGlobalAnsi(strProxy)
struct_IPI.proxyBypass = Marshal.StringToHGlobalAnsi("local")
' Allocating memory
Dim intptrStruct As IntPtr = Marshal.AllocCoTaskMem(Marshal.SizeOf(struct_IPI))
' Converting structure to IntPtr
Marshal.StructureToPtr(struct_IPI, intptrStruct, True)
Dim iReturn As Boolean = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY, intptrStruct, System.Runtime.InteropServices.Marshal.SizeOf(struct_IPI))
End Sub
答案 0 :(得分:0)
对于Firefox:您可以将设置添加到文件&#34; prefs.js&#34;发现于:
C:\ Users \用户名\应用程序数据\漫游\ Mozilla的\火狐\概况\ ???默认
只需在文件末尾添加以下行:
user_pref("network.proxy.ftp", "localhost");
user_pref("network.proxy.ftp_port", 10);
user_pref("network.proxy.http", "localhost");
user_pref("network.proxy.http_port", 10);
user_pref("network.proxy.socks", "localhost");
user_pref("network.proxy.socks_port", 10);
user_pref("network.proxy.ssl", "localhost");
user_pref("network.proxy.ssl_port", 10);
user_pref("network.proxy.type", localhost);