繁体   English   中英

在Windows Phone Runtime 8.1中获取url参数

[英]Get url parameters in Windows Phone Runtime 8.1

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

msft- {的ProductID}://授权/ =的access_token {用户访问令牌}&expires_in = {期满的时的令牌}?

我需要获取access_token变量的值。

这里已经回答了同样的问题: 从.NET中的字符串中获取url参数 ,但不幸的是,Windows Phone 8.1运行时中不存在HttpUtility。 有没有替代HttpUtility.ParseQueryString?

从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"]);
        }

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM