المساعد الشخصي الرقمي

مشاهدة النسخة كاملة : reddit.com bot



C# Programming
04-25-2009, 03:52 AM
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/**********;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.******Container = new ******Container();
request.******Container.Add(******s);
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();
******s.Add(response.******s);
Encoding enc = System.Text.Encoding.UTF8;
StreamReader sr = new StreamReader(response.GetResponseStream(), enc, true);
s=sr.ReadToEnd();
return s;
// }
//catch (Exception ex)
//{
// MessageBox.Show("Error: " + ex.Message, "Error", MessageBoxButtons.OK, MessageBoxIcon.Information);
// Console.WriteLine(ex.Message);

// return string.Empty;
//}

}



this code is working for url:www.reddit.com correctly.
ok its ok

but for login i am not getting correct url (Live http header software plugin in firfox)

i am getting www.reddit.com/api/login/

but this is not working

im geting error. 404 page not found.


could you please give me idea.

yogesh