0

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.

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.

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();

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?

Thanks in advance.

abatishchev
  • 98,240
  • 88
  • 296
  • 433
Trav L
  • 14,732
  • 6
  • 30
  • 39
  • possible duplicate http://stackoverflow.com/questions/2499568/how-to-set-a-proxy-for-webbrowser-control-without-effecting-the-system-ie-proxy/2504683#2504683 – Sheng Jiang 蒋晟 Mar 26 '10 at 11:36
  • That looks like it should have worked, but if it's not, you probably need to implement an IHTTPNegotiate callback and add your code there. – EricLaw Mar 05 '11 at 14:49

1 Answers1

1

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);

where browser is:

public AxWebBrowser browser;
Trav L
  • 14,732
  • 6
  • 30
  • 39
  • Out of curiosity, does that cache the proxy information for all future requests via the webbrowser object? ie if a user then clicks a link in the page rendered in the browser control does that communication channel occur over the proxy as well? – Marcus Pope Dec 16 '10 at 19:14
  • No, that wouldn't work, unless the connection happened to be reused. – EricLaw Mar 05 '11 at 14:47