Pytanie #1:
Mam taki Kod:
CookieContainer m_ccCiastkaPoZalogowaniu;
string m_sTokenM;
private string pobierzToken(string sWtronaWWW)
{
HttpWebRequest request = (HttpWebRequest)WebRequest.Create(sWtronaWWW);
HttpWebResponse response = (HttpWebResponse)request.GetResponse();
StreamReader reader = new StreamReader(response.GetResponseStream());
string kodStrony = reader.ReadToEnd();
response.Close();
reader.Close();
int pozycjaStart = kodStrony.IndexOf("_csrf_token");
kodStrony = kodStrony.Substring(pozycjaStart, kodStrony.Length - pozycjaStart);
kodStrony = kodStrony.Remove(0, 20);
string token = kodStrony.Substring(0, kodStrony.IndexOf("\""));
token = token.Replace("/", "%2F");
token = token.Replace("+", "%2B");
token = token.Replace("=", "%3D");
//MessageBox.Show(token);
return token;
}
try
{
m_sTokenM = pobierzToken("http://fileshark.pl/zaloguj");
string username = "sileent";
string password = "dude901";
String postData = string.Format("_username={0}&_password={1}&_csrf_token={2}&submit=Zaloguj", username, password, m_sTokenM);
CookieContainer tymczasoweCiastka = new CookieContainer();
UTF8Encoding kodowanie = new UTF8Encoding();
Byte[] byteData = kodowanie.GetBytes(postData);
HttpWebRequest postRequest = (HttpWebRequest)WebRequest.Create("http://fileshark.pl/zaloguj");
postRequest.Method = "POST";
postRequest.KeepAlive = true;
postRequest.CookieContainer = tymczasoweCiastka;
postRequest.ContentType = "application/x-www-form-urlencoded";
postRequest.Referer = string.Format("http://fileshark.pl/");
postRequest.UserAgent = "Mozilla/5.0 (Windows NT 6.2; rv:11.0) Gecko/20100101 Firefox/11.0";
Stream postRequestStream = postRequest.GetRequestStream();
postRequestStream.Write(byteData, 0, byteData.Length);
postRequestStream.Close();
HttpWebResponse postResponse;
postRequest.ServicePoint.Expect100Continue = false;
postResponse = (HttpWebResponse)postRequest.GetResponse();
tymczasoweCiastka.Add(postResponse.Cookies);
m_ccCiastkaPoZalogowaniu = tymczasoweCiastka;
StreamReader postRequestReader = new StreamReader(postResponse.GetResponseStream());
string resultSource = postRequestReader.ReadToEnd();
metroTextBox1.Text = resultSource;
}
catch (System.Exception ex)
{
MessageBox.Show(ex.Message);
}
próbuje się zalogować na podaną stronę, lecz mimo pobierania tokenu cały czas wyświetla mi stronę startową. Wydaje mi się, że gdzieś może być błąd z ciastkami ale męczę się z tym już cały dzień i nic mi nie przychodzi do głowy.
Pytanie #2
Na stronie rapidu.net jest bardzo podobny formularz lecz nie posiada on "name" same id, jak poprzez HttpWebRequest mogę się do tego zabrać aby móc się zalogować?