關於windows phone教務線上用戶端

來源:互聯網
上載者:User

標籤:

本人是個大二學生,由於學校的教務線上一直沒出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教務線上用戶端

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.