Since Http实用程序 http://msdn.microsoft.com/en-us/library/system.web.httputility.aspx在 WinRT 中不可用,我想知道是否有一种简单的方法来解析 HTTP 查询字符串?
实际上有一些相当于HttpUtility.ParseQueryString http://msdn.microsoft.com/en-gb/library/system.web.httputility.parsequerystring.aspx在 WinRT 中?
代替HttpUtility.ParseQueryString
您可以使用WwwFormUrlDecoder http://msdn.microsoft.com/en-us/library/windows/apps/hh825884.aspx.
这是我抓住的一个例子here http://www.dzhang.com/blog/2012/08/21/parsing-uri-query-strings-in-windows-8-metro-style-apps
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];
});
}
}
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)