Ich versuche gerade mir eine Art Bot für
zu schreiben. Ich scheitere schon am einloggen mit den Webrequests -.- Bei mir wird immer eine Webexception aufgerufen -.-
Wenn ich mir das ganze in Fiddler anschaue kann ich auch auf Anhieb keinen Unterschied erkennen ausser dass wenn ich mich normal über die Seite einlogge ein POST-Request auf /get_address.php geschieht und dann eine Weiterleitung auf /index.php die mit dem HTTP Status 200 endet.
Wenn ich allerdings meinen Code ausprobiere bekomme ich nur eine ständige Weiterleitung (Http Status 302) und es wird eine WebException ausgelöst.
Code:
namespace primedice
{
public class clsFunctions
{
private string userAgent = "Mozilla/5.0 (Windows NT 6.1; rv:26.0) Gecko/20100101 Firefox/26.0";
private CookieContainer cookies;
private const string sHostURL = "https://primedice.com";
public clsFunctions()
{
this.cookies = new CookieContainer();
}
public string login(string sPath, string sParameter)
{
sPath = "/get_address.php";
sParameter = "id=81028&password=.wyp%29%3CYKgwDT*l4";
string message;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] postData = encoding.GetBytes(sParameter);
this.cookies = new CookieContainer();
System.Net.ServicePointManager.Expect100Continue = false;
try
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sHostURL + sPath);
request.Method = "POST";
request.UserAgent = this.userAgent;
request.CookieContainer = this.cookies;
request.Referer = sHostURL + "/login.php";
request.ContentType = "application/x-www-form-urlencoded";
request.ContentLength = postData.Length;
request.AllowAutoRedirect = true;
request.MaximumAutomaticRedirections = 10;
Stream dataStream = request.GetRequestStream();
dataStream.Write(postData, 0, postData.Length);
dataStream.Close();
WebResponse response = request.GetResponse();
MessageBox.Show(((HttpWebResponse)response).StatusDescription);
message = new StreamReader(response.GetResponseStream()).ReadToEnd();
}
catch (WebException exep)
{
MessageBox.Show(exep.Status.ToString());
MessageBox.Show(((HttpWebResponse)exep.Response).StatusCode.ToString());
MessageBox.Show(((HttpWebResponse)exep.Response).StatusDescription);
message = "Login";
}
return message;
}
}
}
möglicherweise die Lösung ist, allerdings leider nein.Hat wer einen anderen Lösungsansatz für mich? :/






