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 ...
 
随机推荐
- ajax省市区三级联动
			
jdbc+servlet+ajax开发省市区三级联动 技术点:jdbc操作数据库,ajax提交,字符拦截器,三级联动 特点:局部刷新达到省市区三级联动,举一反三可以做商品分类等 宗旨:从实战中学习 博 ...
 - web开发工具软件使用问题记录
			
一.右键 - 添加Git Bash Here菜单 转自:http://blog.csdn.net/u014527912/article/details/51723735 步骤: 1.通过在“运行”中输 ...
 - java.lang.OutOfMemoryError: Java heap space的解决方法
			
windows->preferences->Java->Installed JRES->edit->Default VM Arguments添加-Xms256m -Xmx ...
 - Global.asax 文件是什么
			
Global.asax 文件,有时候叫做 ASP.NET 应用程序文件,提供了一种在一个中心位置响应应用程序级或模块级事件的方法.你可以使用这个文件实现应用程序安全性以及其它一些任务.下面让我们详细看 ...
 - 选择什么样的DOCTYPE
 - [转]Centos7下caffe的安装
			
Centos7下caffe的安装 原文地址:http://blog.csdn.net/s2392735818/article/details/49796017 版权声明:本文为博主原创文章,未经博 ...
 - [Docker]Docker快速上手学习笔记
			
0. 学习的一些疑问 如何热更新镜像(images)?(你可以快速启动或者销毁容器.这种时间几乎是实时的) 如何热更新游戏服? 好处在于各个应用之间环境相互独立,即使某一个容器崩溃也不会影响到其它容器 ...
 - 按Enter键触发事件
			
1.document.onkeydown=function(e){ var keycode=document.all?event.keyCode:e.which; if(k ...
 - adb devices 端口占用
			
一. 1.通过cmd命令,输入adb devices查看连接设备时,报错 2 .通过adb nodaemon server 查看adb server绑定的端口.提示“通过每个套接字地址只能使用一次” ...
 - curl+openssl编译
			
curl不支持openssl的静态库,所以编译openssl的时候,应该加上shared 参数,记录一下我亲手编译的参数: ./configure --prefix=/usr/local/openss ...