How to access wikipedia

I want to access HTML content from wikipedia. But it shows that access is denied.

How can I access the Wiki. Please give some suggestion

+2


source to share


1 answer


Use HttpWebRequest

Try the following:



string Text = "http://www.wikipedia.org/";
HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(Text);
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 7.0; Windows NT 6.0)";
HttpWebResponse respons;
respons = (HttpWebResponse)request.GetResponse();
Encoding enc = Encoding.GetEncoding(respons.CharacterSet);
StreamReader reader = new StreamReader(respons.GetResponseStream(), enc);
string sr = reader.ReadToEnd();

      

+6


source







All Articles