ExampleCodeAs follows:
WebProxy proxy = new WebProxy ("XXX. XXX", Port );
Proxy. Credentials = new networkcredential ("user", "pass", "Domain ");
// For domain user authentication, you can directly use: credentialcaches. defaultcredential;
// Prepare Web request...
Httpwebrequest myrequest = (httpwebrequest) webrequest. Create ("http://www.google.com ");
Myrequest. method = "get ";
Myrequest. Proxy = proxyie;
Description
1. Create a WebProxy, specify the proxy IP address and port, and set its credentials, that is, the user/password to log on to the proxy server;
2. Set the proxy attribute of webrequest
If it is a WebService, it also has the proxy attribute, and the settings are the same.
The above code is in a non-Asp.net WebProgramBut the web program also needs to add the following items in Web. config:
<System.net>
<Defaultproxy>
<Proxy
Usesystemdefault = "false"
Proxyaddress = "http://XXX.XXX.XXX: Port"
Bypassonlocal = "true"
/>
</Defaultproxy>
</System.net>
In. NET 2.0 has the auto proxy detection mechanism, which can automatically obtain proxy settings and try all possible proxies in a certain order. The advantage is that you do not need to set a proxy information in the code, you can obtain the latest proxy settings without restarting the application. for details, see the reference address below.
Unsolved problems:
Like QQ, proxy settings are allowed to be set to IE, that is, you do not need to enter the proxy server information again and directly use the settings in IE. no solution has been found.
Ref:
Http://msdn.microsoft.com/msdnmag/issues/05/08/AutomaticProxyDetection/default.aspx
Http://support.microsoft.com/default.aspx? SCID = KB; en-US; 330221