windows phone 8.1教务在线客户端(后续)
经过了一番折腾,这个wp教务在线算是告一段落了,其实原理很简单,就是post方式访问登陆页面返回cookie,然后带着这个cookie用get方式继续访问你想要访问并取回内容的页面,而且httpclient会默认保存cookie的,这个关键我一开始就没搞清,以至于走了弯路,,
ok,这个项目我只是登陆并且获取了我想要的html内容,至于解析html,可以用正则表达式,等以后有时间再研究吧
下面是源码:
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 Windows.Web.Http;
namespace App
{
public sealed partial class MainPage : Page
{
public MainPage()
{
this.InitializeComponent(); this.NavigationCacheMode = NavigationCacheMode.Required;
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
}
//点击登陆按钮
private async void button_Click(object sender, RoutedEventArgs e)
{
//这个uri是抓包获得的,就是那个带有post请求的uri
var uri = "xxx";
var values = new List<KeyValuePair<string, string>>();
//这个键值对也是抓包获得的,就是你的用户名和密码填上
values.Add(new KeyValuePair<string, string>("自己的用户名", "xxxxx"));
values.Add(new KeyValuePair<string, string>("自己的密码", "xxxxxx"));
string response = await App.httpClientHelper.Post(new Uri(uri), values);
//string responsetext = await response.Content.ReadAsStringAsync();
//这个uri是你想获得返回内容的uri
var _uri = "你想访问的uri";
string _response = await App.httpClientHelper.Get(new Uri(_uri));
Frame.Navigate(typeof(BlankPage1), _response);
}
}
}
<Page
x:Class="App.MainPage"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid>
<Button x:Name="button" Content="Login" Click="button_Click" HorizontalAlignment="Left" Margin="232,292,0,0" VerticalAlignment="Top"/> <TextBox x:Name="textBox1" HorizontalAlignment="Left" Margin="201,138,0,0" TextWrapping="Wrap" VerticalAlignment="Top" Width="166"/>
<TextBlock x:Name="textBlock" HorizontalAlignment="Left" Margin="43,138,0,0" TextWrapping="Wrap" Text="Name" FontSize="30" VerticalAlignment="Top" Height="39" Width="116"/>
<TextBox x:Name="passwordBox" HorizontalAlignment="Left" Margin="201,218,0,0" VerticalAlignment="Top" Width="166"/>
<TextBlock x:Name="textBlock1" HorizontalAlignment="Left" Margin="43,218,0,0" TextWrapping="Wrap" Text="Password" FontSize="22" VerticalAlignment="Top" Height="39" Width="93"/> </Grid>
</Page>
这个是个空页面,里面放着所返回的html源码:
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; namespace App
{
public sealed partial class BlankPage1 : Page
{
public BlankPage1()
{
this.InitializeComponent();
} protected override void OnNavigatedTo(NavigationEventArgs e)
{
textBox.Text = e.Parameter.ToString();
}
}
}
<Page
x:Class="App.BlankPage1"
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
xmlns:local="using:App"
xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
mc:Ignorable="d"
Background="{ThemeResource ApplicationPageBackgroundThemeBrush}"> <Grid>
<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"/> </Grid>
</Page>
这是自定义的httpClienthelper类:
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using Windows.Web.Http; namespace App
{
public class HttpClientHelper
{
private HttpClient httpClient; public HttpClientHelper()
{
httpClient = new HttpClient(); } public async Task<string> Post(Uri uri, IList<KeyValuePair<string, string>> postcontent)
{
string responseText = string.Empty;
HttpResponseMessage response = await httpClient.PostAsync(uri, new HttpFormUrlEncodedContent(postcontent));
responseText = await response.Content.ReadAsStringAsync();
return responseText;
} public async Task<string> Get(Uri uri)
{
string responseText = string.Empty;
HttpResponseMessage response = await httpClient.GetAsync(uri);
responseText = await response.Content.ReadAsStringAsync();
return responseText;
}
}
}
一定别忘了在app.xaml.cs里实例化这个httpClientHelper实例:
public static HttpClientHelper httpClientHelper = new HttpClientHelper();
好了,这只是基本的原理展示,这是我学习windows phone的一个小尝试。
windows phone 8.1教务在线客户端(后续)的更多相关文章
- Windows phone8.1教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下 由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实 ...
- 关于windows phone教务在线客户端
本人是个大二学生,由于学校的教务在线一直没出windows phone的教务在线,而且本身也对wp开发感兴趣,所以就尝试着开发一下 由于没有系统的学习,只能在摸索中前进,这背后的原理很简单,可不容易实 ...
- Windows苹果安卓手机远程桌面客户端推荐
适用于:Windows 10.Windows 8.1.Windows Server 2012 R2.Windows Server 2016 最近公司电脑从Windows7升级到了Windows10,然 ...
- 常量,字段,构造方法 调试 ms 源代码 一个C#二维码图片识别的Demo 近期ASP.NET问题汇总及对应的解决办法 c# chart控件柱状图,改变柱子宽度 使用C#创建Windows服务 C#服务端判断客户端socket是否已断开的方法 线程 线程池 Task .NET 单元测试的利剑——模拟框架Moq
常量,字段,构造方法 常量 1.什么是常量 常量是值从不变化的符号,在编译之前值就必须确定.编译后,常量值会保存到程序集元数据中.所以,常量必须是编译器识别的基元类型的常量,如:Boolean ...
- Windows下配置Git服务器和客户端 超全
为了配合Redmine使用,特地用Git来做版本控制. Git Candy© 是一个基于ASP.NET MVC的Git分布式版本控制平台,Git Candy的目标是轻松干掉Bonobo,逐渐追赶Git ...
- Windows下编译打包Spice PC客户端
目录 1 环境搭建 2 编译客户端 3 打包客户端 1 环境搭建 1.1 准备工作 安装启动: 安装替换图标工具: Resource Hacker 安装exe制作工具: NSIS(提取码:3dfp ...
- c++ 网络编程(一)TCP/UDP windows/linux 下入门级socket通信 客户端与服务端交互代码
原文作者:aircraft 原文地址:https://www.cnblogs.com/DOMLX/p/9601511.html c++ 网络编程(一)TCP/UDP 入门级客户端与服务端交互代码 网 ...
- 正方教务系统客户端 error loading midas.dll.
在windows xp/7/10上安装了客户端,安装到注册字体一步,没有响应,强行结束.启动客户端,登录,出现 error loading midas.dll. 32位:先将 midas.dll 放 ...
- windows上搭建NFS服务器及客户端 挂载
在Windows相关系统上搭建NFS服务及客户端挂载 有两种方式: 第一种: (Windows Server2008R2等类似企业版这样的版本的Server服务上有自带的NFS服务进行搭建) (特别 ...
随机推荐
- Huffman编码
#define _CRT_SECURE_NO_WARNINGS #include <iostream> #include <cstdio> #include <cstri ...
- js 让浏览器全屏模式的方法launchFullscreen
浏览器全屏模式的启动函数requestFullscreen仍然需要附带各浏览器的js方言前缀 // 判断各种浏览器,找到正确的方法 function launchFullscreen(element) ...
- FileReader对象
在一些项目中,经常会遇到图片上传的情况,为了提高用户体验,一般会要求选择图片后 能预览一下图片. 以前的做法是 通过 ajax上传图片后,然后再显示出来,这样会产生大量的无用的图片文件,在HTML5的 ...
- [题解]洛谷月赛 Hello World(升级版)
题目背景 T1答案要mod1000000007(10^9+7),请重新提交,非常抱歉! 一天,智障的pipapi正在看某辣鸡讲义学程序设计. 题目描述 在讲义的某一面,他看见了一篇文章.这篇文章由英文 ...
- PHP获取具有相同name的多个input表单信息
首先是表单应该这样写,注意每个 name="name[]"后面是有一个方括号的.这是PHP特有的获取具有相同name的多个input元素value的方法.(复选框也是采用这种方法) ...
- oracle10g、oracle client和plsql devement 三者之间的关系
oracle10g是服务器,如果本机安装了oracle10g,没有必要安装oracle client,只要配置好DNS,就可以使用plsql devement连接 当然你也可以同时安装orac ...
- My安卓知识5--百度地图api的使用,周边信息检索
虽然查了很多资料,但是这个问题还是解决不了,不知道为什么检索城市内的相关信息能用,检索周边信息语句就是用不了.代码如下,第一段是检索保定市内的加油站,第二段是检索周边的加油站.centerToMyLo ...
- vertx简单客户端创建
import java.util.HashMap;import java.util.Map; import com.yunva.vertx.test.vertproject.util.JsonUtil ...
- Keep It Simple Stupid!
Kelly Johnson提出了KISS原则.他是一个飞机工程师以及航空发明家,同时也是一个管理天才,他一生中主要设计了40多架飞机,获得的荣誉相当之多,总之,很牛. 这个原则是对Johnson带领的 ...
- UIAlertController、UIAlertAction 警告框
NS_CLASS_AVAILABLE_IOS(8_0) @interface UIAlertAction : NSObject <NSCopying> //创建操作 + (instan ...