本人是个大二学生,由于学校的教务在线一直没出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教务在线客户端的更多相关文章

  1. windows phone 8.1教务在线客户端(后续)

    经过了一番折腾,这个wp教务在线算是告一段落了,其实原理很简单,就是post方式访问登陆页面返回cookie,然后带着这个cookie用get方式继续访问你想要访问并取回内容的页面,而且httpcli ...

  2. Windows phone8.1教务在线客户端

    本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下 由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实 ...

  3. windows下的mysql客户端mysqlworkbench链接虚拟机上CentOS的mysql服务器

    本人在虚拟机上CentOS的Linux环境下安装了mysql服务器,在本地Windows下安装了mysql的客户端mysqlworkbench ,所以就想让windows下的mysql客户端mysql ...

  4. 在Ubuntu6.06 在搭建SVN服务器及在windows建立svn+ssh客户端 (续)

    接上篇.本篇主要介绍windows下建立svn+ssh客户端. 9.在windows下安装svn客户端,则需安装“TortoiseSVN”.“Puttygen”和“Pageant”    9.1.下载 ...

  5. 在windows下的hdfs客户端编写

    在windows下的hdfs客户端编写 新建一个工程,右键 properties -> java build path -> libraries 和之前一样的操作,这次 new 一个 us ...

  6. Windows Live Write 日志客户端

    下载地址 下载地址:http://wl.dlservice.microsoft.com/download/E/4/9/E494934D-C33E-486A-AB1A-82248C800922/zh-c ...

  7. 您应该了解的 Windows Azure 网站在线工具

     编辑人员注释:本文章由Windows Azure 网站团队的软件开发者 Amit Apple 撰写. 如果想要了解并亲身参与计算资源管理,那么您一定会很高兴得知这一消息:Windows Azur ...

  8. Windows下安装Redis客户端

    Redis是有名的NoSql数据库,一般Linux都会默认支持.但在Windows环境中,可能需要手动安装设置才能有效使用.这里就简单介绍一下Windows下Redis服务的安装方法,希望能够帮到你. ...

  9. windows安装Redis和客户端

    一.Windows安装Redis 1.下载安装包Redis-x64-3.0.504.zip到本地 2.解压 3.打开CMD,切换到解压后的redis目录,然后 C:\Users\Administrat ...

随机推荐

  1. 修改ubuntu中usr文件夹的权限后,sudo后出现sudo:must be setuid root问题的解决方案

    无意之间,使用sudo chmod -R 777 /usr命令修改了usr文件的所有者,导致sudo:must be setuid root问题的出现,即sudo命令无法使用.网上介绍的方法差不多都相 ...

  2. MD5编码的内存泄露

    MD5CryptoServiceProvider 如果多次使用会产生内存溢出,如下这样调用几百万次就会出现内存 溢出. public static string MD5Encode(string so ...

  3. 【摘】BPMN2.0-概要

    BPMN2.0-概要   原文地址:http://www.uml.org.cn/workclass/201206272.asp 作者:AliKevin2011,发布于2012-6-27   一.BPM ...

  4. sql脚本查询日期时间段日期

    ---列举指定时间月份DECLARE @date1 VARCHAR(10) , @date2 VARCHAR(10)SET @date1 = '2010-01-01'SET @date2 = '201 ...

  5. 【转载】SQL Server 2008 r2 中 SQL语句中单引号转义

    sql server有两个转义符. 默认情况下, 单引号'是字符串的边界符, 如果在字符串中包含单引号', 则必须使用两个单引号', 第1个单引号'就是转义符.

  6. 复制mueclipse项目到eclipse

    本文适用于将MyEclipse上的项目projectA检出后重命名为projectB的情况,如果只是检出projectA到Eclipse,也可以部分参考 1.从svn上检出Myeclipse项目到Ec ...

  7. iOS开发时,在Xcode中添加多个Targets进行版本控制

    在iOS开发中,很可能有以下场景:需要开发多个版本,或因需区分收费版,免费版,或因为网络环境需要区分测试版,发布版,或因渠道不同需要区分企业版,AppStore版等等.解决办法无非就是CheckOut ...

  8. 服务器Linux系统安全维护基础知识介绍

    事先规划好Linux操作系统的分区 Linux操作系统的分区规划跟微软操作系统的分区规划不同.后者分区规划对于其性能的影响很小.但是Linux操作系统的分区规划则不同,其对服务器的性能影响很大.其实我 ...

  9. canvas beginPath()

    先举个简单的例子, var myCanvas = document.getElementById("myCanvas"); var context= myCanvas.getCon ...

  10. C# 读取Excel文件里面的内容到DataSet

    摘要:读取Excel文件里面的内容到DataSet 代码: /// <summary> /// 读取Excel文件里面的内容到DataSet /// </summary> // ...