我很难保存会话或者在我的代码中可以调用的任何内容。有人可以帮帮忙吗?这是代码的一部分:
public void dOR()
{
HttpWebRequest rr = (HttpWebRequest)WebRequest.Create("https://www.deviantart.com/users/login");
string post_data = "ref=https%3A%2F%2Fwww.deviantart.com%2F&username=user&password=pass&remember_me=1";
rr.ContentType = "application/x-www-form-urlencoded";
rr.Method = WebRequestMethods.Http.Post;
rr.AllowAutoRedirect = true;
byte[] array1 = Encoding.ASCII.GetBytes(post_data);
rr.ContentLength = array1.Length;
Stream newStream = rr.GetRequestStream();
newStream.Write(array1 , 0, array1 .Length);
newStream.Close();
HttpWebResponse resp = (HttpWebResponse)rr.GetResponse();
using (StreamReader sr = new StreamReader(resp.GetResponseStream()))
{
string sourceCode = sr.ReadToEnd();
textBox1 .Text = sourceCode;
}
}
现在 - 如何让程序保持在会话中?比如,该网站仍然识别我登录的帐户?
我可以将它合并到私有方法中,例如:
private void button1_Click(object sender, EventArgs e)
{
//Send a request again, but preserve the session.
}
非常感谢你们!