我有一個關於登錄到網站的問題,這裏是我的代碼(Visual Studio 2010中,表單應用程序)(也我有點新手)登錄通過C#網站
我應該添加到我的形式?我試圖做到但我做不到。
HttpWebRequest request;
HttpWebResponse response;
CookieContainer cookies;
string url = string.Format("http://extabit.com/login.jsp.login={0}&passwd={1}", cboUserName.Text, txtPassWord.Text);
request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
response = (HttpWebResponse)request.GetResponse();
if (response.StatusCode != HttpStatusCode.Found)
{
//ToDo: if the page wasn't found raise Exception
//instead of this textmessage
MessageBox.Show("Something Wrong");
response.Close();
request.KeepAlive = false;
return;
}
cookies = request.CookieContainer;
response.Close();
request = (HttpWebRequest)WebRequest.Create(http://extabit.com);
request.AllowAutoRedirect = false;
request.CookieContainer = cookies;
response = (HttpWebResponse)request.GetResponse();
using (Stream s = response.GetResponseStream())
{
StreamReader sr = new StreamReader(s);
string line;
while (!sr.EndOfStream)
{
//todo read the page contents
}
「我試圖做到這一點,但我做不到」這不是一個很好的問題描述。什麼不起作用?你期望什麼沒有發生?錯誤?例外? – Oded
當我將它添加到新窗體中時,我收到18錯誤。如何防止它們,這是我的問題。或者我做錯了嗎? (我提到我是新手)http://lulzimg.com/view/6993bcd989.jpg –
什麼錯誤?什麼樣的錯誤? – Oded