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 ...
随机推荐
- SQL 查询性能优化----解决书签查找
先来看看什么是书签查找: 当优化器所选择的非聚簇索引只包含查询请求的一部分字段时,就需要一个查找(lookup)来检索其他字段来满足请求.对一个有聚簇索引的表来说是一个键查找(key lookup), ...
- python autopep8
安装 使用pip install autopep8或easy_install 都可以. 使用 autopep8 -i -a 要检查的py文件路径 更多参数使用可以参考:https://github.c ...
- JAVA学习笔记(一):一个小爬虫的例子
1.import java.io.*; java.io.*不是一个文件,而是一组类.它是在java.io包里的所有类,*是通配符,比如a*.txt代表的就是以a开头的所有txt文件,“?”是单个词 ...
- (转)testng对失败时截图处理
写这篇微博之前,自动化测试代码中有对于失败测试截图的功能,但是却散落在各个catch语句块中.不便于以后的扩展和维护,AOP思想里说明是面向切面编程,把公共的组件提取出来,可以单独修改维护. 但是直到 ...
- Mysql插入数据为何要加上" ` "(Esc下面那个按键符号)?
资料上和以前学习的SQL语言,往数据库里面插入数据语句是这样的 INSERT INTO test_table (clo_1, col_2) VALUES("this is value of ...
- JavaSE基础知识总结
最近回顾了一下Java的基础知识,决定写成博客梳理一遍,主要是JavaSE部分最基础的知识,适合考前突击,学后回顾,不适合作为初学材料. 简单的列个目录吧: 一.数据类型和运算符 二.流程控制与数组 ...
- 近期微博吐槽言论存档,涉及“性能优化”、C++陋习等
写C++程序的几个陋习:class 名以大写 C 开头,例如 CDate:成员变量以 m_ 开头:变量采用匈牙利命名法:不知道何时禁用 copy-ctor/assign operator.前三个可能是 ...
- 关于SharePoint 2010中不能使用AjaxControlToolkit的解决办法
因为项目中有一个需求需要使用calendar控件,而且样式要和Reporting Service中的尽量一致,搜索了很久发现还是微软的AjaxControlToolkit提供的CalendarExte ...
- 解析jquery获取父窗口的元素
("#父窗口元素ID",window.parent.document); 对应javascript版本为window.parent.document.getElementByIdx ...
- css3之多列