关于windows phone教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下
由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实现,网上也没合适的教程,下面是本人尝试着写登录页面的代码,
不过还是有些语法上的问题,希望有贵人相助
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Runtime.InteropServices.WindowsRuntime;
using Windows.Foundation;
using Windows.Foundation.Collections;
using Windows.UI.Xaml;
using Windows.UI.Xaml.Controls;
using Windows.UI.Xaml.Controls.Primitives;
using Windows.UI.Xaml.Data;
using Windows.UI.Xaml.Input;
using Windows.UI.Xaml.Media;
using Windows.UI.Xaml.Navigation;
using System.Collections.Specialized;
using System.Text;
using System.Xml.Linq;
using System.Threading.Tasks;
using System.Text.RegularExpressions;
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required;
}
private async void button_Click(object sender, RoutedEventArgs e)
{
//这句postdata的拼写可能有错误,考虑用键值对的方式
string loginstr = "j_username=" + textBox1.Text + "&j_password=" + passwordBox.ToString(); CookieContainer cookie = await GetCookie(loginstr,"http://60.18.131.131:11080/newacademic/common/security/login.jsp");
string content = await GetContent(cookie, "http://60.18.131.131:11080/newacademic/frameset.jsp");
Frame.Navigate(typeof(BlankPage1), content);
textBox2.Text = content;
} public async Task<CookieContainer> GetCookie (string postString,string postUrl)
{
CookieContainer cookie = new CookieContainer();
HttpWebRequest httpRequest = (HttpWebRequest)WebRequest.Create(postUrl);
//下面这个请求头的信息不知如何改进啊,反正有什么我就把它添上了
httpRequest.CookieContainer = cookie;//设置cookie
httpRequest.Method = "POST";//POST提交
httpRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
httpRequest.ContentType = "application/x-www-form-urlencoded";
byte[] bytes = System.Text.Encoding.UTF8.GetBytes(postString);
Stream stream = await httpRequest.GetRequestStreamAsync();
stream.Write(bytes, 0, bytes.Length);//以上是post数据的写入,不知还有什么疏漏之处
HttpWebResponse httpResponse =(HttpWebResponse)await httpRequest.GetResponseAsync();
return cookie;
} public async Task<string> GetContent(CookieContainer cookie,string url)
{
string content;
HttpWebRequest httpRequest = (HttpWebRequest)HttpWebRequest.Create(url);
httpRequest.CookieContainer = cookie;
httpRequest.Accept = "text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,*/*;q=0.8";
httpRequest.ContentType = "application/x-www-form-urlencoded";
httpRequest.Method = "GET";
HttpWebResponse httpResponse = (HttpWebResponse)await httpRequest.GetResponseAsync();
using(Stream responseStream = httpResponse.GetResponseStream())
{
using (StreamReader sr = new StreamReader(responseStream,System.Text.Encoding.UTF8))
{
content = sr.ReadToEnd();
}
}
return content;
}
}
}
逻辑上大致是先模拟登陆,然后拿到cookie,再带着这个cookie访问登陆上的网页,(然后通过解析html获取自己想要的内容,这部分还没做)
不过并不能取到所返回的content,希望有经验的园友指导一下
关于windows phone教务在线客户端的更多相关文章
- windows phone 8.1教务在线客户端(后续)
经过了一番折腾,这个wp教务在线算是告一段落了,其实原理很简单,就是post方式访问登陆页面返回cookie,然后带着这个cookie用get方式继续访问你想要访问并取回内容的页面,而且httpcli ...
- Windows phone8.1教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下 由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实 ...
- windows下的mysql客户端mysqlworkbench链接虚拟机上CentOS的mysql服务器
本人在虚拟机上CentOS的Linux环境下安装了mysql服务器,在本地Windows下安装了mysql的客户端mysqlworkbench ,所以就想让windows下的mysql客户端mysql ...
- 在Ubuntu6.06 在搭建SVN服务器及在windows建立svn+ssh客户端 (续)
接上篇.本篇主要介绍windows下建立svn+ssh客户端. 9.在windows下安装svn客户端,则需安装“TortoiseSVN”.“Puttygen”和“Pageant” 9.1.下载 ...
- 在windows下的hdfs客户端编写
在windows下的hdfs客户端编写 新建一个工程,右键 properties -> java build path -> libraries 和之前一样的操作,这次 new 一个 us ...
- Windows Live Write 日志客户端
下载地址 下载地址:http://wl.dlservice.microsoft.com/download/E/4/9/E494934D-C33E-486A-AB1A-82248C800922/zh-c ...
- 您应该了解的 Windows Azure 网站在线工具
编辑人员注释:本文章由Windows Azure 网站团队的软件开发者 Amit Apple 撰写. 如果想要了解并亲身参与计算资源管理,那么您一定会很高兴得知这一消息:Windows Azur ...
- Windows下安装Redis客户端
Redis是有名的NoSql数据库,一般Linux都会默认支持.但在Windows环境中,可能需要手动安装设置才能有效使用.这里就简单介绍一下Windows下Redis服务的安装方法,希望能够帮到你. ...
- windows安装Redis和客户端
一.Windows安装Redis 1.下载安装包Redis-x64-3.0.504.zip到本地 2.解压 3.打开CMD,切换到解压后的redis目录,然后 C:\Users\Administrat ...
随机推荐
- Android 7.0 UICC 分析(一)
UICC(Universal Intergrated Circuit Card) 框架 * Following is class diagram for uicc classes: * * UiccC ...
- 解决 VMWARE MAC 10.12无法全屏的问题
昨天我在VMware上装了10.10,然后通过APP store 升级了系统到 10.12,升级前安装VMware tools 能自动全屏,可是升级后不行. 然后在网上查了很多资料,发现并没有这方面的 ...
- KMP匹配算法
先来说一下回溯法匹配字符串: 对于主字符串有一个target_index,以target_index(不动)为起点,匹配字符串pattern的长度+target_index为终点,逐个进行比较,当发现 ...
- 利用命令行将项目传到github上的简单操作
(1)安装git后,打开cmd,进入要上传的文件夹中: (2)输入git init初始化本地git仓库: (3)git add .将所有文件提交到暂存区: (4)git commit -m'说明文字' ...
- MVC随笔之基础数据维护(MVC4+Boostrap)
一般的管理系统都会设定一些basedata,方便用户交互,以前一直用webform开发,各种粘贴复制已经感觉没啥新意了(我是老油条...),现在公司开始接手第一个MVC项目,所以今天写下MVC中的ba ...
- PHP函数的实现原理及性能分析
前言 在任何语言中,函数都是最基本的组成单元.对于php的函数,它具有哪些特点?函数调用是怎么实现的?php函数的性能如何,有什么使用建议?本文将从原理出发进行分析结合实际的性能测试尝试对这些问题进行 ...
- My97Datepicker 去掉 “不合法格式或超期范围”自动纠错限制
官网上,纠错有以下三种,如日期格式不对,或超期,则必须纠错过后,才能继续操作, 但有时,可能允许出错,需要把纠错功能去掉,则可以设置errDealMode = 3,这种模式是官网说没有的, 但能够去掉 ...
- js(ext)中,设置[!!异步!!]上传的简单进度条
代码在updateHmis的历史记录中,此处存档 handler : function() { //显示进度条 Ext.MessageBox.wait('数据上传中...','提示'); //上传数据 ...
- 当我我们用new操作符创建对象的时候,都发生了些什么?
//下面这段代码是javascript设计模式与开发实践上的一段代码 function Person( name ){ this.name = name; }; ...
- 大前端学习笔记整理【五】关于JavaScript中的关键字——this
写在前面 工作有那么一段时间了,但是在工作中,发现自己的理论知识还是有所欠缺.特别是在javascript上,很多东西其实自己属于知道要用这个,但是不知道为什么要这么用...这种情况很是尴尬了,所以写 ...