码迷,mamicode.com
首页 > Windows程序 > 详细

关于windows phone教务在线客户端

时间:2015-11-21 22:23:25      阅读:439      评论:0      收藏:0      [点我收藏+]

标签:

本人是个大二学生,由于学校的教务在线一直没出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;

// “空白页”项模板在 http://go.microsoft.com/fwlink/?LinkId=391641 上有介绍

namespace App3
{
    /// <summary>
    /// 可用于自身或导航至 Frame 内部的空白页。
    /// </summary>
    public sealed partial class MainPage : Page
    {
        public MainPage()
        {
            this.InitializeComponent();

            this.NavigationCacheMode = NavigationCacheMode.Required;
        }


        //这是一个按钮的事件,点击时会登录教务在线,并跳转到另一个页面上显示课程信息
        private void button_Click(object sender, RoutedEventArgs e)
        {
            //这是想调用下面的方法,不知对不对,希望园友相助
            AsyncCallback callBack = new AsyncCallback(ReadCallback);
            
        }

        private void ReadCallback(IAsyncResult asynchronousResult)
        {

            //这是登录页面的uri
            string loginuri = "http://60.18.131.131:11080/newacademic/common/security/login.jsp";
            HttpWebRequest request = (HttpWebRequest)WebRequest.Create(loginuri);
            //设置post的一些信息
            request.Method = "POST";
            request.ContentType = "application/x-www-form-urlencoded";
            request.Credentials = new NetworkCredential(textBox1.Text, passwordBox.ToString());
                       
            HttpWebResponse response = (HttpWebResponse)request.EndGetResponse(asynchronousResult);
            //获取cookie
            CookieCollection cookies = response.Cookies;            
            
            //这是已经登录的uri
            string posturl = "http://60.18.131.131:11080/newacademic/j_acegi_security_check";
            HttpWebRequest req = (HttpWebRequest)WebRequest.Create(posturl);
            //req.CookieContainer = new CookieContainer();
            //req.CookieContainer.Add(posturl,response.Cookies);
            //cookie是如何加入到请求头里去的还有待探讨
            req.Headers["Cookie"] = cookies.ToString();
            //这里我拿到返回的stream
            Stream stream = req.EndGetRequestStream(asynchronousResult);
            StreamReader sr = new StreamReader(stream);
            string content = sr.ReadToEnd();
            //把stream放置到另一个页面里
            Frame.Navigate(typeof(BlankPage1),content);

        }

逻辑上大致是先模拟登陆,然后拿到cookie,再带着这个cookie访问登陆上的网页,(然后通过解析html获取自己想要的内容,这部分还没做)

不过还有一些问题,希望有经验的园友指导一下

关于windows phone教务在线客户端

标签:

原文地址:http://www.cnblogs.com/harrymusic/p/4984730.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!