Iam登錄遇到嚴重問題。我不能使用WebBrowser類登錄到網站,因爲WebBrowser只是單線程類。我無法使用WebClient登錄,因爲我沒有Cookie。試着用HttpWebRequest和蔭猜我成功地登錄,因爲我得到了與頭登入:login.success或類似的東西,但是當我retreived源頁面,它返回我登錄頁顯示我蔭沒有登錄。使用WebClient或HttpWebRequest登錄
蔭嘗試登錄此頁面:https://lite.betfair.com/Login.do?s=000009z
網址的請求: https://lite.betfair.com/SLoginsubmit.do?s=000009z&secure=true&username=user&password=pass
代碼:
HttpWebRequest request;
HttpWebResponse response;
CookieContainer cookies;
string url = "https://lite.betfair.com/SLoginsubmit.do?s=000009z&secure=true&username=user&password=pass";
request = (HttpWebRequest)WebRequest.Create(url);
request.AllowAutoRedirect = false;
request.CookieContainer = new CookieContainer();
response = (HttpWebResponse)request.GetResponse();
cookies = request.CookieContainer;
response.Close();
request = (HttpWebRequest)WebRequest.Create("https://lite.betfair.com/Events.do?s=000209z");
request.AllowAutoRedirect = false;
request.CookieContainer = cookies;
response = (HttpWebResponse)request.GetResponse();
using (Stream s = response.GetResponseStream())
{
StreamReader sr = new StreamReader(s);
string line;
line = sr.ReadToEnd();
}
這聽起來像你沒有將cookie從登錄響應傳遞到下一個請求。發佈你的代碼,我們會幫你弄清楚。 – 2012-02-17 22:42:15