C # capture webpage content after using httpwebrequest to pass proxy server verification .....
Source: Internet
Author: User
String urlstr = "http://www.domain.com"; // specifies the URL to be retrieved
Httpwebrequest HWR = (httpwebrequest) httpwebrequest. Create (urlstr); // create an httpwebrequest object
HWR. Timeout = 60000; // defines the time when the server exceeds the time limit.
WebProxy proxy = new WebProxy (); // defines a relational object
Proxy. Address = new uri ("http://proxy.domain.com: 3128"); // web server: Port
Proxy. Credentials = new networkcredential ("f3210316", "6978233"); // use the secret name, secret
HWR. usedefaultcredentials = true; // users access the website
HWR. Proxy = proxy; // set the network relationship
Httpwebresponse hwrs = (httpwebresponse) HWR. getresponse (); // Get Response
Stream S = hwrs. getresponsestream (); // get the response Stream Object
Streamreader sr = new streamreader (S, encoding. utf8); // take the stream with UTF-8 too many bytes
Stringbuilder content = new stringbuilder ();//
While (Sr. Peek ()! =-1) // fetch a row for each commit
{// NO content exists for the next word
Content. append (Sr. Readline () + "\ r \ n"); // The end is returned.
}//
Return content. tostring (); // return the string
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.