用C#做校园网登陆软件 每次上外网时都得先上学校网站,打开IP控制网关,输入用户名和密码才能联外网,如何编个Windows程序,在其中输入用户名和密码确定后就联外网,请高手指点 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 学校网站用的web page等,要么你的windows程序能够知道如何发送http请求等,用你的用户名和密码发送到学校的服务器 简单问题复杂化并不好。你首先要知道那个web page的表单格式,然后用HttpWebRequest直接发送数据包。 表单格式是不是指这个:<form name="ipgwform" action="/ipgw/ipgw.ipgw" method="post">用户名(Username):<input type="text" name="uid" SIZE=16 MAXLENGTH=15><br>密 码(Password):<input type="password" autocomplete="on" name="password" SIZE=16 MAXLENGTH=15>从网上找的代码:string userID = "uid=" + textBoxUserID.Text; string password = "password=" + textBoxPassword.Text; string postdata = userID + password; ASCIIEncoding encoding = new ASCIIEncoding(); byte[] data = encoding.GetBytes(postdata); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://ipgw.neu.edu.cn/"); myRequest.Method = "POST"; myRequest.ContentType = "application/x-www-form-urlencoded"; myRequest.ContentLength = data.Length; Stream newStream = myRequest.GetRequestStream(); // Send the data. newStream.Write(data, 0, data.Length); newStream.Close(); // Get response HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse(); StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default); string content = reader.ReadToEnd(); label1.Text = content;运行以后提示:远程服务器返回错误:(405)不允许的方法请大家指点一下 1 发送的地址应该是 http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw2 post的数据格式如下:uid=zhang3&password=12345678,你的显然少了 & 符号 一个简单的bat脚本即可解决,我们学校也是这样参见我的博客http://www.cnblogs.com/beanfrog/archive/2010/08/09/auto_auth_connect.html@echo offset Username=填上学号set Password=填上密码explorer "http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw?uid=%Username%&&password=%Password%&&range=2&&timeout=1&&operation=disconnectall"ping -n 2 127.0.0.1 >NUL 2>NULtaskkill /im iexplore.exeexplorer "http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw?uid=%Username%&&password=%Password%&&range=2&&timeout=1&&operation=connect"ping -n 2 127.0.0.1 >NUL 2>NULtaskkill /im iexplore.exe 怎样才能学好面向对象,求指导 Linq查询xml报错 是不是我方法写错了? Dictionary(TKey, TValue)枚举项错位问题。 DES\ECB算法加密解密的例子(C#) 关于BinaryReader的问题 100分求三层架构 实现一个简单操作的源代码 基于C#的文档管理器如何架构? 求救啊!!!!!!!!! 怎么样获取Richtextbox的行列以及行高,行宽 关于vb.net中的“文档注释标记”的问题。 有关C#接口的一点疑问 我想学习下=>或者还有什么高级语法,请高人赐教
你首先要知道那个web page的表单格式,然后用HttpWebRequest直接发送数据包。
<form name="ipgwform" action="/ipgw/ipgw.ipgw" method="post">用户名(Username):<input type="text" name="uid" SIZE=16 MAXLENGTH=15><br>密 码(Password):<input type="password" autocomplete="on" name="password" SIZE=16 MAXLENGTH=15>
从网上找的代码:
string userID = "uid=" + textBoxUserID.Text;
string password = "password=" + textBoxPassword.Text;
string postdata = userID + password;
ASCIIEncoding encoding = new ASCIIEncoding();
byte[] data = encoding.GetBytes(postdata); HttpWebRequest myRequest = (HttpWebRequest)WebRequest.Create("http://ipgw.neu.edu.cn/");
myRequest.Method = "POST";
myRequest.ContentType = "application/x-www-form-urlencoded";
myRequest.ContentLength = data.Length;
Stream newStream = myRequest.GetRequestStream(); // Send the data.
newStream.Write(data, 0, data.Length);
newStream.Close(); // Get response
HttpWebResponse myResponse = (HttpWebResponse)myRequest.GetResponse();
StreamReader reader = new StreamReader(myResponse.GetResponseStream(), Encoding.Default);
string content = reader.ReadToEnd();
label1.Text = content;
运行以后提示:远程服务器返回错误:(405)不允许的方法
请大家指点一下
2 post的数据格式如下:uid=zhang3&password=12345678,你的显然少了 & 符号
参见我的博客http://www.cnblogs.com/beanfrog/archive/2010/08/09/auto_auth_connect.html@echo offset Username=填上学号
set Password=填上密码explorer "http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw?uid=%Username%&&password=%Password%&&range=2&&timeout=1&&operation=disconnectall"
ping -n 2 127.0.0.1 >NUL 2>NUL
taskkill /im iexplore.exeexplorer "http://ipgw.neu.edu.cn/ipgw/ipgw.ipgw?uid=%Username%&&password=%Password%&&range=2&&timeout=1&&operation=connect"
ping -n 2 127.0.0.1 >NUL 2>NUL
taskkill /im iexplore.exe