C# WebBrowser Control Proxy
private Uri currentUri;
private void Form1_Load(object sender, EventArgs e)
{
currentUri = new Uri(@"http://www.stackoverflow.com");
HttpWebRequest myRequest = (HttpWebRequest) HttpWebRequest.Create("http://www.stackoverflow.com");
//WebProxy myProxy = new WebProxy("208.52.92.160:80");
//myRequest.Proxy = myProxy;
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
webBrowser1.DocumentStream = myResponse.GetResponseStream();
webBrowser1.Navigating += new WebBrowserNavigatingEventHandler(webBrowser1_Navigating);
}
void webBrowser1_Navigating(object sender, WebBrowserNavigatingEventArgs e)
{
if (e.Url.AbsolutePath != "blank")
{
currentUri = new Uri(currentUri, e.Url.AbsolutePath);
HttpWebRequest myRequest = (HttpWebRequest)HttpWebRequest.Create(currentUri);
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
webBrowser1.DocumentStream = myResponse.GetResponseStream();
e.Cancel = true;
}
}
You'll have to play with it a little, but I was able to browse around the site.
Or you can try modifying the WebRequest.DefaultWebProxy setting:
http://msdn.microsoft.com/en-us/library/system.net.webrequest.defaultwebproxy.aspx
Set a proxy in C#?
By default, your C# code will use the system proxy set in your IE connection settings.
If you want to be explicit, you can do it via config under System.net:
<defaultProxy useDefaultCredentials="true">
<proxy usesystemdefault="true" proxyaddress="[proxy address]" bypassonlocal="true" />
</defaultProxy>
Programmatically, you can set the proxy:
http://msdn.microsoft.com/en-us/library/system.net.webproxy.aspx
WebProxy proxyObject = new WebProxy("http://proxyserver:80/",true);
WebRequest req = WebRequest.Create("http://www.contoso.com");
req.Proxy = proxyObject;
EDIT:
For web browser control, try this SO post: (disclaimer - haven't tried that)
How to set a proxy for Webbrowser Control without effecting the SYSTEM/IE proxy
Set Proxy Credential in Web Browser Control
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;
Specify Proxy for WebBrowser control in WP7, WP8
The WebBrowser
control is tied to the OS, therefore inheriting the proxy settings that are definied by the user of the device. You can't directly modify them, unless you want to intercept navigation events and feed them directly to your server.
Related Topics
Setting the Datasource for a Local Report - .Net & Report Viewer
Does Anyone Know of a Good C# API for Subversion
How to Get Character for a Given Ascii Value
How to Use C# 8 with Visual Studio 2017
Get the Application Pool Identity Programmatically
Use Linq to Generate Direct Update Without Select
How to Make Correct Date Format When Writing Data to Excel
In C# Why Can't a Conditional Operator Implicitly Cast to a Nullable Type
Why Is 16 Byte the Recommended Size for Struct in C#
How to Translate a List<String> into a SQLparameter for a SQL in Statement
Windows Authentication in ASP.NET 5
Linq to Xml - Update/Alter the Nodes of an Xml Document
Changing Read Only Properties with Reflection
Print HTML Document from Windows Service Without Print Dialog
C# MACro Definitions in Preprocessor
Linq: from a List of Type T, Retrieve Only Objects of a Certain Subclass S