校园网每次出校访问外网都要在login填写表单,包括用户名和密码。设计软件能够自动出校。应该有人做过类似的,请介绍下基本原理,并附上核心代码。谢谢。
网上有段代码,请帮忙分析下,谢谢:
WebRequest webRequest = WebRequest.Create(@"http://10.188.0.43/a01.htm");
try
{
if (((args.Length == 0 && username == "" && password == "")||i!="2")&&args.Length!=3)
{
Console.WriteLine("请输入校园网用户名,并按回车");
username = Console.ReadLine();
Console.WriteLine("请输入校园网密码,并按回车");
password = Console.ReadLine();
}
else if (username == "" && password == "")
{
username = args[0];
password = args[1];
}
}
catch (Exception e)
{
Console.WriteLine("用户名密码获取出错");
//ch = Console.Read();
}
Stream os = null;
try
{
Console.WriteLine("开始连接");
//webRequest = WebRequest.Create(@"http://10.188.0.43/a01.htm");
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes("DDDDD=" + username + "&upass=" + password + "&0MKKey=%B5%C7%C2%BC+Login");
webRequest.ContentLength = bytes.Length; //Count bytes to send
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Send it
Console.WriteLine("正在连接...");
}
catch (Exception e2)
{
Console.WriteLine(e2.Message);
//ch = Console.Read();
}
finally
{
if (os != null)
{
os.Close();
}
}
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{
Console.WriteLine("服务器没有返回信息");
}
else
{
StreamReader sr = new StreamReader(webResponse.GetResponseStream(), Encoding.Default);
string response = sr.ReadToEnd();
网上有段代码,请帮忙分析下,谢谢:
WebRequest webRequest = WebRequest.Create(@"http://10.188.0.43/a01.htm");
try
{
if (((args.Length == 0 && username == "" && password == "")||i!="2")&&args.Length!=3)
{
Console.WriteLine("请输入校园网用户名,并按回车");
username = Console.ReadLine();
Console.WriteLine("请输入校园网密码,并按回车");
password = Console.ReadLine();
}
else if (username == "" && password == "")
{
username = args[0];
password = args[1];
}
}
catch (Exception e)
{
Console.WriteLine("用户名密码获取出错");
//ch = Console.Read();
}
Stream os = null;
try
{
Console.WriteLine("开始连接");
//webRequest = WebRequest.Create(@"http://10.188.0.43/a01.htm");
webRequest.ContentType = "application/x-www-form-urlencoded";
webRequest.Method = "POST";
byte[] bytes = Encoding.ASCII.GetBytes("DDDDD=" + username + "&upass=" + password + "&0MKKey=%B5%C7%C2%BC+Login");
webRequest.ContentLength = bytes.Length; //Count bytes to send
os = webRequest.GetRequestStream();
os.Write(bytes, 0, bytes.Length); //Send it
Console.WriteLine("正在连接...");
}
catch (Exception e2)
{
Console.WriteLine(e2.Message);
//ch = Console.Read();
}
finally
{
if (os != null)
{
os.Close();
}
}
try
{ // get the response
WebResponse webResponse = webRequest.GetResponse();
if (webResponse == null)
{
Console.WriteLine("服务器没有返回信息");
}
else
{
StreamReader sr = new StreamReader(webResponse.GetResponseStream(), Encoding.Default);
string response = sr.ReadToEnd();
解决方案 »
免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货