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 ...
随机推荐
- DateTime.Compare用法
DateTime.Compare(t1,t2)比较两个日期大小,排前面的小,排在后面的大,比如:2011-2-1就小于2012-3-2返回值小于零: t1 小于 t2. 返回值等于零 : t1 等于 ...
- 创建并追加img元素(jquery!)
有几种方法 但都需要你指定一个节点 根据这个节点进行添加 如现有一节点Id为pr:一,向该节点内部后方添加:1 $("#pr").append("<img src= ...
- 使用visio 2007对现有的数据库进行反向工程
假如你有一个数据库并且想对这个数据库进行ER图的描绘:又或者你想绘制一个ER图,但发觉绘制效率太低,对visio不熟悉,而你对数据库的操作却了如指掌.这时候你可以利用Visio的反向工程对已有的数据库 ...
- Checkpoints codeforces 709B
http://codeforces.com/problemset/problem/709/B 题意:给出一条横向坐标轴,给出Vasya所在的坐标位置及其另外n个坐标.Vasya想要至少访问n-1个位置 ...
- 使用AS编译jni文件无法编译出arm64-v8a,x86_64和mips64平台的.so文件的解决方法
我用的插件版本是:classpath 'com.android.tools.build:gradle-experimental:0.4.0',AS集成和使用ndk编译项目参考官方demo:https: ...
- NC JDK报tools.jar错误(61版本)
添加jdk/lib目录下的tools.jar 然后设置环境变量
- 第一章 jQuery基础方法回顾
jQuery即JavaScript,它是一个.js文件(官网下载).使用时须将jQuery库的声明写在HTML文档的head标签里. 章节内容: 1.选择DOM节点 2.延迟的JavaScript的执 ...
- 如何查看SharePoint未知错误的详细信息
在sharepoint 开发的时候,需要查看具体的sharepoint报错信息需要在配置文件中配置如下 通过下面方法就可以直接在出错页面查看错误信息.修改Web应用程序根目录上的Web.config文 ...
- oracle创建密码文件的语句
orapwd file=$ORACLE_HOME/dbs/orapw$ORACLE_SID password=oracle entries=5;
- 有关tp里搜索框的实现方法
1: