昨天选选修课,要登录学校的选课系统,按照大四、大三、大二的顺序依次开放选课权限。听说有工具可以绕开限制提前选课,网上搜索一下还真找到了,是一个使用javascript实现的,整个只有一个页面, 我也保持一份:/Files/lulu/xk.rar。大致上,它使用xmlHttpRequest向服务器发送ajax选课请求。
JS不太熟悉,发现HttpRequest功能差不多,用它试试啦,但是不知道提交数据怎么组织,革命尚未成功但是还是学到了点东西,就在这了写下来了:
//Get请求方式
private string RequestGet(string Url)
{
string PageStr = string.Empty;//用于存放还回的html
Uri url = new Uri(Url);//Uri类 提供统一资源标识符 (URI) 的对象表示形式和对 URI 各部分的轻松访问。就是处理url地址
try
{
HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(url);//根据url地址创建HTTpWebRequest对象
参数设置
HttpWebResponse response = (HttpWebResponse)httprequest.GetResponse();//使用HttpWebResponse获取请求的还回值
Stream steam = response.GetResponseStream();//从还回对象中获取数据流
StreamReader reader = new StreamReader(steam, Encoding.GetEncoding("gb2312"));//读取数据Encoding.GetEncoding("gb2312")指编码是gb2312,不让中文会乱码的
PageStr = reader.ReadToEnd();
reader.Close();
}
catch (Exception e)
{
PageStr += e.Message;
}
return PageStr;
}
private string RequestGet(string Url)
{
string PageStr = string.Empty;//用于存放还回的html
Uri url = new Uri(Url);//Uri类 提供统一资源标识符 (URI) 的对象表示形式和对 URI 各部分的轻松访问。就是处理url地址
try
{
HttpWebRequest httprequest = (HttpWebRequest)WebRequest.Create(url);//根据url地址创建HTTpWebRequest对象
参数设置
HttpWebResponse response = (HttpWebResponse)httprequest.GetResponse();//使用HttpWebResponse获取请求的还回值
Stream steam = response.GetResponseStream();//从还回对象中获取数据流
StreamReader reader = new StreamReader(steam, Encoding.GetEncoding("gb2312"));//读取数据Encoding.GetEncoding("gb2312")指编码是gb2312,不让中文会乱码的
PageStr = reader.ReadToEnd();
reader.Close();
}
catch (Exception e)
{
PageStr += e.Message;
}
return PageStr;
}
private string RequestPost(string Url,string Context)//两个参数分别是Url地址和Post过去的数据
{
string PageStr=string.Empty;
Uri url = new Uri(Url);
byte[] reqbytes=Encoding.ASCII.GetBytes(Context);
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "post";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = reqbytes.Length;
Stream stm = req.GetRequestStream();
stm.Write(reqbytes, 0, reqbytes.Length);
stm.Close();
HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
Stream stream = wr.GetResponseStream();
StreamReader srd= new StreamReader(stream,Encoding.GetEncoding("gb2312"));
PageStr += srd.ReadToEnd();
stream.Close();
srd.Close();
}
catch (Exception e)
{
PageStr += e.Message;
}
return PageStr;
}
{
string PageStr=string.Empty;
Uri url = new Uri(Url);
byte[] reqbytes=Encoding.ASCII.GetBytes(Context);
try
{
HttpWebRequest req = (HttpWebRequest)WebRequest.Create(url);
req.Method = "post";
req.ContentType = "application/x-www-form-urlencoded";
req.ContentLength = reqbytes.Length;
Stream stm = req.GetRequestStream();
stm.Write(reqbytes, 0, reqbytes.Length);
stm.Close();
HttpWebResponse wr = (HttpWebResponse)req.GetResponse();
Stream stream = wr.GetResponseStream();
StreamReader srd= new StreamReader(stream,Encoding.GetEncoding("gb2312"));
PageStr += srd.ReadToEnd();
stream.Close();
srd.Close();
}
catch (Exception e)
{
PageStr += e.Message;
}
return PageStr;
}