2010-12-09 29 views
0

我正在使用c#,Microsoft AjaxToolKit。如何从C#中的登录框发送HTTPS请求#

我使用ajaxToolkit:ModalPopupExtender登录页,现在是什么我想,在我的登录页应该发送的HTTPS请求 POST用于记录用户的认证。下面是点击登录按钮时我的代码的快照。

protected void LoginBtn_Click(object sender, EventArgs e) 
    { 
     //Add your DB Authentication Module here.... 
     //This is just for testing 
     if (loginId.Text.Equals("user") && pwd.Text.Equals("user")) 
      successLabel.Text = "Welcome User"; 
     else 
      successLabel.Text = "Authentication Failed...Retry"; 
     successLabel.Visible = true; 
     Loginlnk.Visible = false; 
     Signuplnk.Visible = true; 
    } 

以上代码仅用于测试目的,请建议如何继续使用POST HTTPS WEB REQUEST来验证有效用户。

谢谢。

回答

1

string username = "user"; 
string password = "pass"; 
HttpWebRequest request = (HttpWebRequest)WebRequest.Create("https://www.yoursite.com"); 
request.UserAgent = "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1; .NET CLR 1.0.3705)"; 

request.Method = "POST"; 

using (StreamWriter writer = new StreamWriter(request.GetRequestStream(), Encoding.ASCII)) 
{ 
    writer.Write("nick=" + username + "&password=" + password); 
} 
+0

感谢@LAS_VEGAS,我将送我的用户名和密码,POST数据,所以我在哪里需要发送作进一步处理的要求,我意思是我们必须拨打一些通知或程序,让我们的用户名和密码通过验证,请建议 – 2010-12-09 09:18:56

1

这里对我来说是什么工作:

var request = WebRequest.Create(_url); 
    request.PreAuthenticate = true; 
    request.Credentials = new NetworkCredential(_userName, _password);