获取Windows Phone Runtime 8.1中的url参数

本文关键字:中的 url 参数 Windows Phone Runtime 获取 | 更新日期: 2023-09-27 18:04:47

我有一个像这样的字符串(它是来自Facebook登录对话框的响应):

microsoft - {ProductID}://授权/? access_token = {user-access-token}, expires_in = {expiration-time-of-token}

我需要获得access_token变量的值。

这里已经回答了同样的问题:从。net中的字符串获取url参数,但不幸的是,在Windows phone 8.1运行时不存在HttpUtility。是否有一个替代httutility . parsequerystring ?

获取Windows Phone Runtime 8.1中的url参数

来自MSDN页面http://msdn.microsoft.com/en-us/library/windows/apps/hh825884.aspx:

使用WwwFormUrlDecoder类根据"&"符号的数量和位置将查询字符串分解为名称-值对。每个名称-值对由一个IWwwFormUrlDecoderEntry对象表示。

一个简单的方法是使用正则表达式。这应该可以工作:

        var regex = new System.Text.RegularExpressions.Regex("[?&]access_token(?:=(?<token>[^&]*))?");
        var match = regex.Match (responseString);
        if (match.Success)
        {
            Console.WriteLine (match.Groups["token"]);
        }