[英]Programmatically Set Proxy Address, Port, Username, Password
Hi I need to set proxy address of IE programmatically 嗨,我需要以编程方式设置IE的代理地址
Earlier I used to use this RedTomahawk.TORActivator but it doesnot gives an option to set those proxies which requires username and password. 之前我曾经使用过这个RedTomahawk.TORActivator,但它没有提供设置需要用户名和密码的代理的选项。
How can we set those proxies which needs username and passwords 我们如何设置需要用户名和密码的代理
Please provide examples like 请提供类似的示例
void Setproxy(string ip,string port,string uname,string pwd) { ///Code here }
You could P/Invoke the WinHttpSetDefaultProxyConfiguration function. 你可以P / Invoke WinHttpSetDefaultProxyConfiguration函数。
UPDATE: 更新:
Including example as requested: 包括要求的示例:
[StructLayout(LayoutKind.Sequential, CharSet = CharSet.Unicode)]
public struct WINHTTP_PROXY_INFO
{
public AccessType AccessType;
public string Proxy;
public string Bypass;
}
public enum AccessType
{
DefaultProxy = 0,
NamedProxy = 3,
NoProxy = 1
}
class Program
{
[DllImport("winhttp.dll", CharSet = CharSet.Unicode, SetLastError = true)]
public static extern bool WinHttpSetDefaultProxyConfiguration(ref WINHTTP_PROXY_INFO config);
static void Main()
{
var config = new WINHTTP_PROXY_INFO();
config.AccessType = AccessType.NamedProxy;
config.Proxy = "http://proxy.yourcompany.com:8080";
config.Bypass = "intranet.com";
var result = WinHttpSetDefaultProxyConfiguration(ref config);
if (!result)
{
throw new Win32Exception(Marshal.GetLastWin32Error());
}
else
{
Console.WriteLine("Successfully modified proxy settings");
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.