1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48
|
class WebConnectViaProxy
{
private class MyProxy : IWebProxy
{
private NetworkCredential networkCredential = new NetworkCredential("User", "MotDePasse");
#region IWebProxy Members
public ICredentials Credentials
{
get
{
return networkCredential;
}
set
{
networkCredential = value as NetworkCredential;
}
}
public Uri GetProxy(Uri destination)
{
return new Uri("http://MonProxyUrl");
}
public bool IsBypassed(Uri host)
{
return false;
}
#endregion
}
public void connectWebSite(string url)
{
System.Net.WebClient webc;
String pagestr;
webc = new System.Net.WebClient();
webc.Proxy = (IWebProxy)new MyProxy();
Stream retWeb = webc.OpenRead(url);
System.IO.StreamReader streemr = new System.IO.StreamReader(retWeb);
pagestr = streemr.ReadToEnd();
streemr.Close();
}
} |
Partager