我已經嘗試了一切,我可以在網上找到關於如何實現這個登錄到這個網站。這是最近的失敗。通過C#登錄到網站
// I have tried with multiple different URLS this one
// and http://www.movable.com/login do not throw errors
string url = "http://portal.movable.com/";
string username = "<myusername>";
string password = "<mypassword>";
string authTok = @"+HOt3NTkkIAHkMSMvzQisEquhun9xvIG1mHzIEh6CAo=";
string postData = "utf8=✓" + "&authenticity_token=" + authTok +
"&user[login]=" + username +
"&user[password]=" + password + "&user[offset]=-5";
var container = new CookieContainer();
var buffer = Encoding.UTF8.GetBytes(postData);
var request = (HttpWebRequest)HttpWebRequest.Create(url);
request.CookieContainer = container;
request.UserAgent = "Mozilla/5.0";
request.Method = "POST";
request.KeepAlive = true;
request.AllowAutoRedirect = true;
request.CookieContainer = container;
request.ContentLength = buffer.Length;
request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
request.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8";
using (var requestStream = request.GetRequestStream())
requestStream.Write(buffer, 0, buffer.Length);
using (var response = request.GetResponse())
{
using (var reader = new StreamReader(response.GetResponseStream()))
{
var result = reader.ReadToEnd();
//this is to read the page source after the request
MessageBox.Show(result);
}
}
而且,這裏是從網站的相關數據(我知道令牌是在我做了他們同樣的例子不同,它不工作)
<form accept-charset="UTF-8" action="/signin" class="new_user" id="new_user" method="post"><div style="margin:0;padding:0;display:inline"><input name="utf8" type="hidden" value="✓" /><input name="authenticity_token" type="hidden" value="hHfoUnIbi+6RB51x1cqXqAYHkjz9mCi7nc86gMdiMOo=" /></div>
<p class="notice">Signed out successfully.</p>
<h2>login to your account</h2>
<label for="user_login">Login</label>
<input id="user_login" name="user[login]" size="30" type="text" />
<label for="user_password">Password</label>
<input id="user_password" name="user[password]" size="30" type="password" />
<input id="user_offset" name="user[offset]" type="hidden" />
<label for="user_remember_me">
<input name="user[remember_me]" type="hidden" value="0" /><input id="user_remember_me" name="user[remember_me]" type="checkbox" value="1" />
Remember me on this computer.
</label>
<button class="login" name="button" type="submit">Login</button>
<a href="https://stackoverflow.com/users/password/new" class="forgotPassword">Forgot password?</a>
</form> </div>
示例HTML表單顯示錶單發佈到/ signin。嘗試將您的網址更改爲http://portal.movable.com/signin。 – Rich 2013-02-16 03:39:46
我嘗試過這個,它會拋出一個錯誤 – 2013-02-16 03:40:15
實際上它在過去拋出一個錯誤,現在它只是像我所有其他人一樣返回到登錄頁面 – 2013-02-16 03:41:07