0
我已經植入了一個登錄代碼到一個網站,然後我想從服務器上下載一個文件。登錄網站並下載文件?
HttpWebRequest http = WebRequest.Create(@"http://www.website.com") as HttpWebRequest;
// http.Connection = "Keep-alive"; //uncertain
http.Method = "POST";
http.ContentType = "application/x-www-form-urlencoded";
string postData = "FormNameForUserId=" + @"username" + "&FormNameForPassword=" + "pass";
byte[] dataBytes = UTF8Encoding.UTF8.GetBytes(postData);
http.ContentLength = dataBytes.Length;
using (Stream postStream = http.GetRequestStream())
{
postStream.Write(dataBytes, 0, dataBytes.Length);
}
HttpWebResponse httpResponse = http.GetResponse() as HttpWebResponse;
// Probably want to inspect the http.Headers here first
http = WebRequest.Create(@"http://www.codeproject.com") as HttpWebRequest;
http.CookieContainer = new CookieContainer();
http.CookieContainer.Add(httpResponse.Cookies);
HttpWebResponse httpResponse2 = http.GetResponse() as HttpWebResponse;
我怎樣才能找到我已經正確地登入,也登錄後下載文件該怎麼辦?