请问怎么设置webbrowser设置代理用户名和密码? RRS feed

  • 问题

  •         public struct Struct_INTERNET_PROXY_INFO
                public int dwAccessType;
                public IntPtr proxy;
                public IntPtr proxyBypass;
            [DllImport("wininet.dll", SetLastError = true)]
            private static extern bool InternetSetOption(IntPtr hInternet, int dwOption, IntPtr lpBuffer, int lpdwBufferLength);
            public void ProxyAuth()
                const int INTERNET_OPTION_PROXY_USERNAME = 43;
                const int INTERNET_OPTION_PROXY_PASSWORD = 44;
                string username = "user";
                string password = "password";
                IntPtr intptrUsername = Marshal.StringToHGlobalAnsi(username);
                bool uReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_USERNAME, intptrUsername, System.Text.Encoding.ASCII.GetByteCount(username));
                IntPtr intptrPassword = Marshal.StringToHGlobalAnsi(password);
                bool pReturn = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_PASSWORD, intptrPassword, System.Text.Encoding.ASCII.GetByteCount(password));


    • 已编辑 xiaoa_m 2012年4月29日 1:42 错了
    2012年4月29日 1:41


  • 看看这个类似的问题:


    var credentialStringValue = "user:pass";
    var credentialByteArray = ASCIIEncoding.ASCII.GetBytes(credentialStringValue);
    var credentialBase64String = Convert.ToBase64String(credentialByteArray);
    Object nullObject = 0;
    Object nullObjectString = "";
    Object authObject = string.Format("Proxy-Authorization: Basic {0}{1}", credentialBase64String, Environment.NewLine);
    browser.Navigate(args.Url, ref nullObject, ref nullObject, ref nullObjectString, ref authObject);


    Mike Feng
    MSDN Community Support | Feedback to us
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    2012年4月30日 11:35