When I started writing a blog reading tool, I always accessed it directly, and the access method was relatively simple:
Webrequest _ HWR = webrequest. createdefault (new system. Uri (URL ));
Webresponse _ hrs = _ HWR. getresponse ();
Stream receivestream = _ hrs. getresponsestream ();
But recently I opened the project and saw that the code was not running normally. After debugging, the client proxy was blocked by its, so I had to find the method for setting proxy access. The original code was very simple, you only need to add the following code.
WebProxy _ Wp = new WebProxy (proxyname, proxyport );
_ WP. bypassproxyonlocal = true;
Icredentials credentials = new networkcredential (username, userkey, domainname );
_ WP. Credentials = credentials;
Webrequest _ HWR = webrequest. createdefault (new system. Uri (URL ));
_ HWR. Proxy = _ WP;
Webresponse _ hrs = _ HWR. getresponse ();
Of course, on msdn, there is another way to use _ HWR. Proxy = _ WP;
Globalproxyselection. Select = _ WP; in fact, this is to set the global proxy service. You do not need to set them one by one. It is easier to capture page data.
Encoding encode = system. Text. encoding. default;
Streamreader sr = new streamreader (receivestream, encode );
String htmlcontent = "";
Char [] READ = new char [256];
Int COUNT = Sr. Read (read, 0,256 );
While (count> 0)
{
String STR = new string (read, 0, count );
Htmlcontent + = STR;
Count = Sr. Read (read, 0,256 );
}
OK. In this way, the code is configured as our proxy and the program is used to access the IE content ~~