1. globalproxyselection class
Global default proxy instance that includes all HTTP requests.
2,CodeExample
If (setting. needproxy)
{
Globalproxyselection. Select = setupproxy ();
}
// Create a new request
Httpwebrequest httpwrequest = (httpwebrequest) webrequest. Create (requesturl );
If (null = httpwrequest)
{
Logger. Write ("Web request failed ");
Return false;
} Private WebProxy setupproxy ()
{
// If a proxyurl is specified in the configuration file,
// Create a WebProxy object for later use.
WebProxy mproxy = NULL;
String proxyurl = Setting. proxyurl;
If (proxyurl! = NULL)
{
Int proxyport = getproxyport ();
If (proxyport> 0)
{
Mproxy = new WebProxy (proxyurl, proxyport );
}
Else
{
Mproxy = new WebProxy (proxyurl );
}
// If a proxyuser is specified in the configuration file,
// Set up the proxy object's credentials.
String proxyuser = Setting. proxyuser;
If (proxyuser! = NULL)
{
String proxypassword = Setting. proxypassword;
String proxydomain = Setting. proxydomain;
If (proxydomain! = NULL)
{
Mproxy. Credentials = new networkcredential (proxyuser, proxypassword, proxydomain );
}
Else
{
Mproxy. Credentials = new networkcredential (proxyuser, proxypassword );
}
}
}
Return mproxy;
}