本文介绍了WinRT中的HttpUtility.ParseQueryString方法在哪里?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

由于WinRT中没有 ,我想知道是否有一种简单的方法来解析HTTP查询字符串?

Since HttpUtility is not available in WinRT, I was wondering if there's a straightforward way to parse HTTP query strings?

实际上有一些等同于

Is there actually some equivalent to HttpUtility.ParseQueryString in WinRT?

推荐答案

您可以使用。

Instead of HttpUtility.ParseQueryString you can use WwwFormUrlDecoder.

这是我抓住的一个例子

Here's an example I grabbed here

using System;
using Microsoft.VisualStudio.TestPlatform.UnitTestFramework;
using Windows.Foundation;

[TestClass]
public class Tests
{
    [TestMethod]
    public void TestWwwFormUrlDecoder()
    {
        Uri uri = new Uri("http://example.com/?a=foo&b=bar&c=baz");
        WwwFormUrlDecoder decoder = new WwwFormUrlDecoder(uri.Query);

        // named parameters
        Assert.AreEqual("foo", decoder.GetFirstValueByName("a"));

        // named parameter that doesn't exist
        Assert.ThrowsException<ArgumentException>(() => {
            decoder.GetFirstValueByName("not_present");
        });

        // number of parameters
        Assert.AreEqual(3, decoder.Count);

        // ordered parameters
        Assert.AreEqual("b", decoder[1].Name);
        Assert.AreEqual("bar", decoder[1].Value);

        // ordered parameter that doesn't exist
        Assert.ThrowsException<ArgumentException>(() => {
            IWwwFormUrlDecoderEntry notPresent = decoder[3];
        });
    }
}

这篇关于WinRT中的HttpUtility.ParseQueryString方法在哪里?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

10-13 16:02