Asp.net tips (III)

Source: Internet
Author: User

How do I download a webpage?
First, use the System. Net. WebRequestFactory class to obtain a WebRequest object:
WebRequest request = WebRequestFactory. Create ("http: // localhost ");
Then the request is answered:
WebResponse response = request. GetResponse ();
The GetResponse method is blocked until the download is complete. Then you can access the response stream as follows:
Stream s = response. GetResponseStream ();
// Output the downloaded stream to the console
StreamReader sr = new StreamReader (s );
String line;
While (line = sr. ReadLine ())! = Null)
Console. WriteLine (line );
Note that the WebRequest and WebReponse objects are backward compatible with HttpWebRequest and HttpWebReponse objects, which are used to access http-related functions.

How to use proxy )?
Two methods-this can affect all Web requests:
System. Net. GlobalProxySelection. Select = new DefaultControlObject ("proxyname", 80 );
In addition, to set proxy services for specific Web requests, do the following:
ProxyData proxyData = new ProxyData ();
ProxyData. HostName = "proxyname ";
ProxyData. Port = 80;
ProxyData. OverrideSelectProxy = true;
HttpWebRequest request = (HttpWebRequest) WebRequestFactory. Create ("http: // localhost ");
Request. Proxy = proxyData;

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.