Что ж, я узнал, как войти на веб-сайт, используя следующий код:
// Create a request using a URL that can receive a post.
WebRequest request = WebRequest.Create ("localhost/shoutbox/index.php");
// Set the Method property of the request to POST.
request.Method = "POST";
// Create POST data and convert it to a byte array.
string postData = "string.Format("username={0}&password={1}", "username", "password")";
byte[] byteArray = Encoding.UTF8.GetBytes (postData);
// Set the ContentType property of the WebRequest.
request.ContentType = "application/x-www-form-urlencoded";
// Set the ContentLength property of the WebRequest.
request.ContentLength = byteArray.Length;
// Get the request stream.
Stream dataStream = request.GetRequestStream ();
// Write the data to the request stream.
dataStream.Write (byteArray, 0, byteArray.Length);
// Close the Stream object.
dataStream.Close ();
// Get the response.
WebResponse response = request.GetResponse ();
// Display the status.
Console.WriteLine (((HttpWebResponse)response).StatusDescription);
// Get the stream containing content returned by the server.
dataStream = response.GetResponseStream ();
// Open the stream using a StreamReader for easy access.
StreamReader reader = new StreamReader (dataStream);
// Read the content.
string responseFromServer = reader.ReadToEnd ();
// Display the content.
Console.WriteLine (responseFromServer);
// Clean up the streams.
reader.Close ();
dataStream.Close ();
response.Close ();
Мне удалось войти, я смог прочитать исходный код и извлечь данные из источникаа также прочитайте StatusCode.Но ... Когда я вошел в систему, мне нужно отправить сообщения на чат, который находится на другой странице (перенаправление после входа в систему): т.е.
localhost / shoutbox / index.php? Page= 2
Находясь на странице 2, я вижу, что есть действие FORM localhost / shoutbox / messages / shout.php? Username = myuser & message = blablah
Я пыталсяотправьте крик, используя новый запрос, основанный на URL-адресе действия FORM:
localhost / shoutbox / messages / shout.php? username = myuser & message = blablah
, но в нем говоритсяне вошли в.Я имею в виду, что я создал новый веб-запрос и хотел бы узнать, как оставаться в системе и отправить сообщение?
- Я также пытался использовать файлы cookie, полученные из предыдущего запроса.но, к сожалению, безуспешно.