HTTP access proxy

Source: Internet
Author: User


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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.