Windows phone8.1教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出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 phone8.1教务在线客户端的更多相关文章
- 关于windows phone教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下 由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实 ...
- windows phone 8.1教务在线客户端(后续)
经过了一番折腾,这个wp教务在线算是告一段落了,其实原理很简单,就是post方式访问登陆页面返回cookie,然后带着这个cookie用get方式继续访问你想要访问并取回内容的页面,而且httpcli ...
- 在本地windows机器上安装SecureCRT客户端
一.SecureCRT客户端介绍. SecureCRT是一款支持SSH(SSH1和SSH2)的终端仿真程序,简单地说是Windows下登录UNIX或Linux服务器主机的软件. SecureCRT支持 ...
- 转Windows Phone8.1 获取手机唯一识别码
转:http://www.dotblogs.com.tw/martinlau17/archive/2014/07/21/146020.aspx 因小弟比較懶,上次不小心 清空了所有文章 現在重寫了XD ...
- Windows Phone8 中如何引用 SQLite 数据库
SQLite数据库介绍 1.SQLite是一款轻型的嵌入式数据库,使用C++开发,使用非常广泛 2.SQLite是一款跨平台的数据库,支持Windows.Linux.Android.IOS.Windo ...
- Windows Phone8 中如何引用 SQLite 数据库2
本博文编写环境 VS2013 + WP8 SDK 上篇介绍完了SQLite在wp中的部署(具体请参阅 Windows Phone8 中如何引用 SQLite 数据库),下面来看如何使用 SQLite ...
- Windows Server 2012远程刷新客户端组策略,IE代理设置
Windows Server 2012远程刷新客户端组策略: 1.PowerShell命令对单台计算机进行刷新: Invoke-GPUpdate -RandomDelayInMinutes 0 -Co ...
- Windows Phone8开发工具包简述(转载)
Windows Phone 软件开发包 (SDK) 8.0 可为您提供开发 Windows Phone 8 和 Windows Phone 7.5 应用和游戏所需的工具. 概述Windows Phon ...
- windows phone8.1:Xml,Json序列化和反序列化
原文:windows phone8.1:Xml,Json序列化和反序列化 小梦本例主要实现以下四点内容: 将Car对象序列化为xml 将Car对象序列化为Json 将xml反序列化为Car对象 将js ...
随机推荐
- [刘阳Java]_快速搭建MyBatis环境_第2讲
1.MyBatis的环境配置 导入MyBatis包, mybatis-3.2.8.jar 导入MySQL驱动包, mysql-connector-java-5.1.24-bin.jar 创建表的实体类 ...
- C# 对Access数据库操作的通用类
(转载自博主Jerry很简单) //Access数据库-C# 操作类 代码using System;using System.Collections.Generic;using System.Linq ...
- 过滤Xss
/** * 防xss过滤 * * @author rentingshuang <tingshuang@rrkd.cn> * @param type $string * @param typ ...
- varnish
html,body,div,span,applet,object,iframe,h1,h2,h3,h4,h5,h6,p,blockquote,pre,a,abbr,acronym,address,bi ...
- Getting Started With Hazelcast 读书笔记(第四章)
第四章 分而治之 在指导了如何进行基本使用之后,又再次进入理论模块. Hazelcast的基本策略就是切片分区,默认是271个片.内置一个 partition table记录那个节点是那个分区,并在h ...
- Jackson fasterxml跟codehaus的区别 (fasterxml vs. codehaus) -- 转载
Jackson fasterxml和codehaus的区别: 他们是Jackson的两大分支.也是两个版本的不同包名.Jackson从2.0开始改用新的包名fasterxml:1.x版本的包名是cod ...
- eclipse在光标停留在同一对象的背景色提示,开启与关闭
eclipse在光标停留在变量上的时候,同一变量能够提示相同的背景色.这个功能感觉不起眼,但是实在是很好用啊.如果不小心点消失了会很麻烦. 这里留个记录,如果关闭了记得开启: 开启关闭的位置在工具栏上 ...
- [10]APUE:信号
[a] 常用信号 SIGABRT 调用 abort 函数时产生此信号,进程异常终止 SIGALRM 调用 alarm 或 setitimer 函数超时之后产生 SIGCHLD 子进程终止或 stop ...
- 将ubuntu的id_rsa秘钥转为putty的ppk格式
1.使用putty的puttygen.exe: 2.导入需要转换的秘钥 3.保存私钥
- tomcat详情
[转载]http://grass51.blog.51cto.com/4356355/1123400