在Web浏览器控件设置代理凭证 [英] Set Proxy Credential in Web Browser Control
问题描述
我工作的一个遗留code其中一个应用程序使用 AxSHDocVw.AxWebBrowser
(不可以 系统。 Windows.Forms.Control
)打开网页,我延长其采取代理到考虑。
I am working on a legacy code where an application uses AxSHDocVw.AxWebBrowser
(not System.Windows.Forms.Control
) to open up web pages and am extending it to take proxy into considerations.
我已经在 http://www.pinvoke.net/default下面的例子的.aspx / WININET / internetsetoption.html 使用 InternetSetOption()
要经过指定的代理和测试,它的作品。
I have following example on http://www.pinvoke.net/default.aspx/wininet/internetsetoption.html to use InternetSetOption()
to go through specified proxy and tested that it works.
现在的障碍是我什么都试过,但未能通过用户名和密码之后code:
Now the hurdle is I tried everything but failed to pass username and password with following code:
//-- Set Proxy Username
bool resultF = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_USERNAME, username, username.Length+1);
var errorF = Marshal.GetLastWin32Error();
//-- Set Proxy Password
bool resultG = InternetSetOption(IntPtr.Zero, INTERNET_OPTION_PROXY_PASSWORD, password, password.Length+1);
var errorG = Marshal.GetLastWin32Error();
两个 resultF
和 resultG
返回真
并具有没有错误,但它仍在工作。对那些原本可以在这里发生的任何提示?做什么方法我一定要调试吗?
Both resultF
and resultG
return true
and has no errors but it still working. Any hint on what may be happening here? and what method do I have to debug this?
在此先感谢。
推荐答案
其实,我发现了一个work'able的解决方案,它是在导航谎言与代理服务器的身份验证标头:
I actually found a work'able solution, where it was lie under navigation with Proxy-Authentication in header:
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);
其中,浏览器
是:
public AxWebBrowser browser;
这篇关于在Web浏览器控件设置代理凭证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!