Próba zalogowanie się na naszą klasę kończy się błędem jak poniżej. Co ważne, identyczny kod ze zmienioną zmienną logonUrl [i postData w odpowiednim formacie] loguje mnie na inne strony.
Myślałem, że może kwestia referera, więc go dodałem - nic to jednak nie zmieniło.
Błąd:
System.Net.WebException: The underlying connection was closed: An unexpected error occurred on a receive. ---> System.IO.IOException: Unable to read data from the transport connection: An existing connection was forcibly closed by the remote host. ---> System.Net.Sockets.SocketException: An existing connection was forcibly closed by the remote host
Kod:
public bool Login() {
Hashtable data = GUI.getData();
string postData = "login=" + data["login"] + "&password=" + data["password"] + "&remember=1";
string logonUrl = "http://nasza-klasa.pl/login";
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(logonUrl);
byte[] bdata = System.Text.ASCIIEncoding.ASCII.GetBytes(postData);
req.ContentLength = bdata.Length;
req.ContentType = "application/x-www-form-urlencoded";
req.Method = "POST";
req.CookieContainer = new CookieContainer();
req.Referer = "http://nasza-klasa.pl/";
Stream reqStream = req.GetRequestStream();
reqStream.Write(bdata, 0, bdata.Length);
reqStream.Close();
HttpWebResponse res = (HttpWebResponse)req.GetResponse(); //<-- błąd
Stream resStream = res.GetResponseStream();
StreamReader reader = new StreamReader(resStream);
string responseData = reader.ReadToEnd();
....