经过了一番折腾,这个wp教务在线算是告一段落了,其实原理很简单,就是post方式访问登陆页面返回cookie,然后带着这个cookie用get方式继续访问你想要访问并取回内容的页面,而且httpclient会默认保存cookie的,这个关键我一开始就没搞清,以至于走了弯路,,

ok,这个项目我只是登陆并且获取了我想要的html内容,至于解析html,可以用正则表达式,等以后有时间再研究吧

下面是源码:

  1. using Windows.UI.Xaml.Controls.Primitives;
  2. using Windows.UI.Xaml.Data;
  3. using Windows.UI.Xaml.Input;
  4. using Windows.UI.Xaml.Media;
  5. using Windows.UI.Xaml.Navigation;
  6. using Windows.Web.Http;
  7. namespace App
  8. {
  9. public sealed partial class MainPage : Page
  10. {
  11. public MainPage()
  12. {
  13. this.InitializeComponent();
  14.  
  15. this.NavigationCacheMode = NavigationCacheMode.Required;
  16. }
  17.  
  18. protected override void OnNavigatedTo(NavigationEventArgs e)
  19. {
  20. }
  21. //点击登陆按钮
  22. private async void button_Click(object sender, RoutedEventArgs e)
  23. {
  24. //这个uri是抓包获得的,就是那个带有post请求的uri
  25. var uri = "xxx";
  26. var values = new List<KeyValuePair<string, string>>();
    //这个键值对也是抓包获得的,就是你的用户名和密码填上
  27. values.Add(new KeyValuePair<string, string>("自己的用户名", "xxxxx"));
  28. values.Add(new KeyValuePair<string, string>("自己的密码", "xxxxxx"));
  29. string response = await App.httpClientHelper.Post(new Uri(uri), values);
  30. //string responsetext = await response.Content.ReadAsStringAsync();
  31. //这个uri是你想获得返回内容的uri
  32. var _uri = "你想访问的uri";
  33. string _response = await App.httpClientHelper.Get(new Uri(_uri));
  34. Frame.Navigate(typeof(BlankPage1), _response);
  35. }
  36. }
  37. }
  1. <Page
  2. x:Class="App.MainPage"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:App"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d"
  9. Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  10.  
  11. <Grid>
  12. <Button x:Name="button" Content="Login" Click="button_Click" HorizontalAlignment="Left" Margin="232,292,0,0" VerticalAlignment="Top"/>
  13.  
  14. <TextBox x:Name="textBox1" HorizontalAlignment="Left" Margin="201,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="166"/>
  15. <TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="43,138,0,0" TextWrapping="Wrap" Text="Name" FontSize="30" VerticalAlignment="Top" Height="39" Width="116"/>
  16. <TextBox x:Name="passwordBox" HorizontalAlignment="Left" Margin="201,218,0,0" VerticalAlignment="Top" Width="166"/>
  17. <TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="43,218,0,0" TextWrapping="Wrap" Text="Password" FontSize="22" VerticalAlignment="Top" Height="39" Width="93"/>
  18.  
  19. </Grid>
  20. </Page>

这个是个空页面,里面放着所返回的html源码:

  1. using Windows.Foundation.Collections;
  2. using Windows.UI.Xaml;
  3. using Windows.UI.Xaml.Controls;
  4. using Windows.UI.Xaml.Controls.Primitives;
  5. using Windows.UI.Xaml.Data;
  6. using Windows.UI.Xaml.Input;
  7. using Windows.UI.Xaml.Media;
  8. using Windows.UI.Xaml.Navigation;
  9.  
  10. namespace App
  11. {
  12. public sealed partial class BlankPage1 : Page
  13. {
  14. public BlankPage1()
  15. {
  16. this.InitializeComponent();
  17. }
  18.  
  19. protected override void OnNavigatedTo(NavigationEventArgs e)
  20. {
  21. textBox.Text = e.Parameter.ToString();
  22. }
  23. }
  24. }
  1. <Page
  2. x:Class="App.BlankPage1"
  3. xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
  4. xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
  5. xmlns:local="using:App"
  6. xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
  7. xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
  8. mc:Ignorable="d"
  9. Background="{ThemeResource ApplicationPageBackgroundThemeBrush}">
  10.  
  11. <Grid>
  12. <TextBox x:Name="textBox" HorizontalAlignment="Left" Margin="55,69,0,0" TextWrapping="Wrap" VerticalAlignment="Top" RenderTransformOrigin="-3.716,-0.387" Height="217" Width="301" BorderThickness="0.1"/>
  13.  
  14. </Grid>
  15. </Page>

这是自定义的httpClienthelper类:

  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.Threading.Tasks;
  6. using Windows.Web.Http;
  7.  
  8. namespace App
  9. {
  10. public class HttpClientHelper
  11. {
  12. private HttpClient httpClient;
  13.  
  14. public HttpClientHelper()
  15. {
  16. httpClient = new HttpClient();
  17.  
  18. }
  19.  
  20. public async Task<string> Post(Uri uri, IList<KeyValuePair<string, string>> postcontent)
  21. {
  22. string responseText = string.Empty;
  23. HttpResponseMessage response = await httpClient.PostAsync(uri, new HttpFormUrlEncodedContent(postcontent));
  24. responseText = await response.Content.ReadAsStringAsync();
  25. return responseText;
  26. }
  27.  
  28. public async Task<string> Get(Uri uri)
  29. {
  30. string responseText = string.Empty;
  31. HttpResponseMessage response = await httpClient.GetAsync(uri);
  32. responseText = await response.Content.ReadAsStringAsync();
  33. return responseText;
  34. }
  35. }
  36. }

一定别忘了在app.xaml.cs里实例化这个httpClientHelper实例:

public static HttpClientHelper httpClientHelper = new HttpClientHelper();

好了,这只是基本的原理展示,这是我学习windows phone的一个小尝试。

windows phone 8.1教务在线客户端(后续)的更多相关文章

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

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

  2. 关于windows phone教务在线客户端

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

  3. Windows苹果安卓手机远程桌面客户端推荐

    适用于:Windows 10.Windows 8.1.Windows Server 2012 R2.Windows Server 2016 最近公司电脑从Windows7升级到了Windows10,然 ...

  4. 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq

    常量,字段,构造方法   常量 1.什么是常量 ​ 常量是值从不变化的符号,在编译之前值就必须确定.编译后,常量值会保存到程序集元数据中.所以,常量必须是编译器识别的基元类型的常量,如:Boolean ...

  5. Windows下配置Git服务器和客户端 超全

    为了配合Redmine使用,特地用Git来做版本控制. Git Candy© 是一个基于ASP.NET MVC的Git分布式版本控制平台,Git Candy的目标是轻松干掉Bonobo,逐渐追赶Git ...

  6. Windows下编译打包Spice PC客户端

    目录 1 环境搭建 2 编译客户端 3 打包客户端   1 环境搭建 1.1 准备工作 安装启动: 安装替换图标工具: Resource Hacker 安装exe制作工具: NSIS(提取码:3dfp ...

  7. c++ 网络编程(一)TCP/UDP windows/linux 下入门级socket通信 客户端与服务端交互代码

    原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/9601511.html c++ 网络编程(一)TCP/UDP  入门级客户端与服务端交互代码 网 ...

  8. 正方教务系统客户端 error loading midas.dll.

    在windows xp/7/10上安装了客户端,安装到注册字体一步,没有响应,强行结束.启动客户端,登录,出现  error loading midas.dll. 32位:先将 midas.dll 放 ...

  9. windows上搭建NFS服务器及客户端 挂载

    在Windows相关系统上搭建NFS服务及客户端挂载  有两种方式: 第一种: (Windows Server2008R2等类似企业版这样的版本的Server服务上有自带的NFS服务进行搭建) (特别 ...

随机推荐

  1. Codeforce 370J Bottles(动态规划-01背包)

    题目链接:http://codeforces.com/problemset/problem/730/J 题目大意:有n个杯子, 每个杯子有两个值一个是已装水量,一个是可装水量.从一个杯子向另一个杯子倒 ...

  2. 附加数据库失败,sql2008,断电数据库日志受损

    附加数据库失败,提示:无法在数据库 'DBNAME' (数据库 ID 为 7)的页 (1:210288) 上重做事务 ID (0:0) 的日志记录或者在重做数据库 'DBNAME' 的日志中记录的操作 ...

  3. CSS3 animation 的尝试

    下面是动画效果: .zoombie { width: 55px; height: 85px; background-image: url("http://images2015.cnblogs ...

  4. WEB中的GET和POST

    客户端提交数据到服务器端有两种方式GET和POST,get是将数据拼接到url上,而post是将数据封装在request body中,发送过去.顾名思义,get即请求数据,有时需要其附带部分参数:po ...

  5. C# SHA1散列算法

    C# SHA1散列算法 /// <summary> /// C# SHA1散列算法 /// </summary> /// <param name="str&qu ...

  6. IntelliJ Idea 集成svn 和使用

    最近公司的很多同事开始使用svn,便尝试了一下,虽然快捷键与eclipse 有些不同,但是强大的搜索功能与"漂亮的界面"(个人认为没有eclipse好看 ),还是值得我们去使用的. ...

  7. 使用dom元素和jquery元素实现简单增删改的练习

    软件开发实际就是数据的增删改查,javascript前端开发也不例外.今天学了jquery框架的简单使用.于是用它实现简单的增删改,接着也用原始的javascript实现同样的功能,以便看出jquer ...

  8. 使用JS脚本获取url中的参数

    第一种方式:使用分隔符及循环查找function getQueryString(name) { // 如果链接没有参数,或者链接中不存在我们要获取的参数,直接返回空 if(location.href. ...

  9. 内省、JavaBean、PropertyDescriptor类、Introspector类、BeanUtils工具包、注解、Rentention、Target、注解的基本属性和高级属性

      本文转载自:http://blog.sina.com.cn/s/blog_5d65a16901011kom.html 关键字:内省.JavaBean.PropertyDescriptor类.Int ...

  10. 提高SQL查询效率(SQL优化)

    要提高SQL查询效率where语句条件的先后次序应如何写 http://blog.csdn.net/sforiz/article/details/5345359   我们要做到不但会写SQL,还要做到 ...