reddit.com bot
-
dear sir, i am trying to access reddit.com through c# code. i am using this code: public void Prepare_Url() { try { string response = Send_Request("http://www.reddit.com", null); string postdata ="op=login-main&user=yogeshyahoo&passwd=yogesh&id=%23login_login-main"; response = Send_Request("http://www.reddit.com", postdata); txtResponse.Text = response; } catch (Exception ex) { Console.WriteLine("Exception" + ex.Message); } } public string Send_Request(string link, string post_data) { //try //{ string url = string.Format(link); HttpWebRequest request = (HttpWebRequest )WebRequest.Create(url); request.UserAgent = "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.8.1.20) Gecko/20081217 Firefox/2.0.0.20"; request.Method = "GET"; request.Accept = "text/xml,application/xml,application/xhtml+xml,text/html,application/json, text/javascript;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5"; request.KeepAlive = true; request.ContentType = @"application/x-www-form-urlencoded"; request.Referer = string.Format("http://www.reddit.com"); request.CookieContainer = new CookieContainer(); request.CookieContainer.Add(cookies); request.Timeout = 600000; request.AllowAutoRedirect = false; //equest.Credentials = new NetworkCredential("yogeshyahoo","yogesh"); request.PreAuthenticate = true; if (post_data != null) {//post the data to the desired link string postData = post_data; request.Method = "POST"; byte[] postBuffer = System.Text.Encoding.GetEncoding(1252).GetBytes(postData); Stream postDataStream = request.GetRequestStream(); postDataStream.Write(postBuffer, 0, postBuffer.Length); postDataStream.Close(); } string s; HttpWebResponse response = (HttpWebResponse)request.GetResponse(); cookies.Add(response.Cookies); E