基本上,我想在C#中使用HTTPWebRequest来访问网页。但是我的程序崩溃了,什么也没发生。
WebProxy myProxy = new WebProxy(prx);
CookieContainer cookieJar = new CookieContainer();
HttpWebRequest request = HttpWebRequest.Create(url) as HttpWebRequest;
request.Method = "GET";
request.Proxy = myProxy;
request.Referer = "http://anyrefererItypehere";
request.CookieContainer = cookieJar;
request.ContentType = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
request.KeepAlive = true;
request.Headers.Add(HttpRequestHeader.AcceptEncoding, "gzip, deflate");
request.UserAgent = "Mozilla/5.0 (Windows NT 5.1; rv:10.0.2) Gecko/20100101 Firefox/10.0.2";
request.Headers.Add(HttpRequestHeader.AcceptLanguage, "Accept-Language: en-us,en;q=0.5");
request.Host = "anyblogItypehere.tumblr.com";
HttpWebResponse webResponse;
webResponse = (HttpWebResponse)request.GetResponse();
Stream stream = webResponse.GetResponseStream();
StreamReader reader = new StreamReader(stream, Encoding.UTF8);
String responseString = reader.ReadToEnd();
webResponse.Close();
rtbSource.Text = responseString;