列举登录:
private void butLogin_Click(object sender, EventArgs e)
{
string zhanghao = this.tetNumber.Text.Trim();
string pwd = this.tetPassWord.Text.Trim();
string port = ConfigurationManager.AppSettings["Port"].ToString();//从配置文件获取端口号
string url = "http://localhost:"+port+"/Login/isVlogin?number="+zhanghao+"&pwd="+pwd+"";
var data = Get(url);
int num;
if (data.Length >10)
{
num = 1;
}
else
{
num = Convert.ToInt32(data);
}
if (num == 0) //从结果中找到
{
Index index = new Index();
//传id可做后面的数据联动
index.StudentNum(zhanghao);
index.Show();
this.Close();
}
else
{
MessageBox.Show("密码或者账号错误!", "提示", MessageBoxButtons.OKCancel, MessageBoxIcon.Error);
return;
}
public static string Get(string url)
{
System.Net.HttpWebRequest myRequest = (System.Net.HttpWebRequest)System.Net.WebRequest.Create(url);
myRequest.Method = "GET"; //获取或设置请求方法
myRequest.ContentType = "application/x-www-form-urlencoded";
System.Net.HttpWebResponse myResponse = (System.Net.HttpWebResponse)myRequest.GetResponse();
System.IO.StreamReader reader = new System.IO.StreamReader(myResponse.GetResponseStream(), System.Text.Encoding.UTF8);
string content = reader.ReadToEnd();
reader.Close();
myResponse.Close(); //关闭响应流
return content;
}