Tôi đã thử mọi thứ tôi có thể tìm thấy trên web về cách thực hiện điều này để đăng nhập vào trang web này. Đây là thất bại gần đây nhất.Đăng nhập vào trang web qua 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);
}
}
Ngoài ra ở đây là liệu có liên quan từ trang web (Tôi biết các mã khác nhau trong ví dụ tôi đã làm cho họ giống nhau và nó không làm việc)
<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>
Biểu mẫu HTML mẫu hiển thị biểu mẫu được đăng lên/đăng nhập. Hãy thử thay đổi url của bạn thành http://portal.movable.com/signin. – Rich
Tôi đã thử điều này và nó ném một lỗi –
Thực tế sửa nó đã ném một lỗi trong quá khứ, bây giờ nó chỉ trả về cho tôi vào trang đăng nhập giống như tất cả những người khác –