本文整理汇总了C#中QueryString.ToString方法的典型用法代码示例。如果您正苦于以下问题:C# QueryString.ToString方法的具体用法?C# QueryString.ToString怎么用?C# QueryString.ToString使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类QueryString
的用法示例。
在下文中一共展示了QueryString.ToString方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: With_no_parameters
public void With_no_parameters()
{
var uri = new Uri("http://foo/bar");
var qs = new QueryString(uri);
qs.ToString().ShouldBe(string.Empty);
qs.ToString(canonical: true).ShouldBe(string.Empty);
}
示例2: BuildAbsolute
/// <summary>
/// Combines the given URI components into a string that is properly encoded for use in HTTP headers.
/// Note that unicode in the HostString will be encoded as punycode.
/// </summary>
/// <param name="scheme">http, https, etc.</param>
/// <param name="host">The host portion of the uri normally included in the Host header. This may include the port.</param>
/// <param name="pathBase">The first portion of the request path associated with application root.</param>
/// <param name="path">The portion of the request path that identifies the requested resource.</param>
/// <param name="query">The query, if any.</param>
/// <param name="fragment">The fragment, if any.</param>
/// <returns></returns>
public static string BuildAbsolute(
string scheme,
HostString host,
PathString pathBase = new PathString(),
PathString path = new PathString(),
QueryString query = new QueryString(),
FragmentString fragment = new FragmentString())
{
var combinedPath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/";
var encodedHost = host.ToString();
var encodedQuery = query.ToString();
var encodedFragment = fragment.ToString();
// PERF: Calculate string length to allocate correct buffer size for StringBuilder.
var length = scheme.Length + SchemeDelimiter.Length + encodedHost.Length
+ combinedPath.Length + encodedQuery.Length + encodedFragment.Length;
return new StringBuilder(length)
.Append(scheme)
.Append(SchemeDelimiter)
.Append(encodedHost)
.Append(combinedPath)
.Append(encodedQuery)
.Append(encodedFragment)
.ToString();
}
示例3: Execute
public virtual IPromise<IHttpResponse> Execute(string method, string baseUrl, QueryString queryString, System.Net.ICredentials credentials, bool async, Action<IHttpRequest> configure)
{
var uri = baseUrl + (queryString == null ? "" : queryString.ToString());
var req = (HttpWebRequest)System.Net.WebRequest.Create(uri);
req.AllowAutoRedirect = this.AllowAutoRedirect;
if (this.AutomaticDecompression) req.AutomaticDecompression = (DecompressionMethods.GZip | DecompressionMethods.Deflate);
if (this.StoreCookies) req.CookieContainer = _cookieContainer;
req.Method = method;
req.ReadWriteTimeout = 300000;
req.Timeout = DefaultTimeout;
if (method == "POST")
{
req.CachePolicy = new RequestCachePolicy(RequestCacheLevel.NoCacheNoStore);
}
req.Credentials = credentials;
var result = new WebRequest(req, this.Compression);
if (configure != null) configure.Invoke(result);
var st = Stopwatch.StartNew();
return result.Execute(async).Convert(r => {
if (r.Core.Cookies.Count > 0) SetCookies(r.Core.Cookies);
return (IHttpResponse)r;
}).Always(() => {
st.Stop();
_httpTracing.TraceData(TraceEventType.Verbose, 0, st.ElapsedMilliseconds);
});
}
示例4: Process
public ActionResult Process(HttpRequestBase request, ModelStateDictionary modelState)
{
IpnVerificationBinder binder = new IpnVerificationBinder();
Transaction tx = binder.Bind(request.Form, modelState);
ContentResult cr = new ContentResult();
cr.ContentEncoding = Encoding.UTF8;
cr.ContentType = "text/html";
cr.Content = "INVALID";
if (tx != null)
{
Transaction dbTx = m_txRepository.GetAll().Where(x => x.Tx == tx.Tx).FirstOrDefault();
if (dbTx != null)
{
string expected = dbTx.ToIpnQueryString().ToString();
QueryString actualQs = new QueryString();
actualQs.Add(request.Form);
actualQs.Remove("cmd");
string actual = actualQs.ToString();
if (expected == actual)
{
cr.Content = "VERIFIED";
}
}
}
return cr;
}
示例5: Creating_from_empty_map
public void Creating_from_empty_map()
{
var args = new Dictionary<string, string>();
var qs = new QueryString(args);
qs.ToString().ShouldBe(string.Empty);
}
示例6: MyFact
public void MyFact()
{
var queryString = new QueryString();
queryString.Add("q", "mcdonald");
Assert.Equal("q=mcdonald", queryString.ToString());
}
示例7: BuildRelative
/// <summary>
/// Combines the given URI components into a string that is properly encoded for use in HTTP headers.
/// </summary>
/// <param name="pathBase">The first portion of the request path associated with application root.</param>
/// <param name="path">The portion of the request path that identifies the requested resource.</param>
/// <param name="query">The query, if any.</param>
/// <param name="fragment">The fragment, if any.</param>
/// <returns></returns>
public static string BuildRelative(
PathString pathBase = new PathString(),
PathString path = new PathString(),
QueryString query = new QueryString(),
FragmentString fragment = new FragmentString())
{
string combinePath = (pathBase.HasValue || path.HasValue) ? (pathBase + path).ToString() : "/";
return combinePath + query.ToString() + fragment.ToString();
}
示例8: ShouldEncodeWhenConvertingToString
public void ShouldEncodeWhenConvertingToString()
{
// arrange
QueryString qs = new QueryString();
qs.Add("1", "http://");
// act and assert
Assert.AreEqual("?1=http%3a%2f%2f", qs.ToString());
}
示例9: ShouldBuildHttpPostString
public void ShouldBuildHttpPostString()
{
// arrange
QueryString qs = new QueryString();
qs.Add("1", "2");
qs.Add("3", "4");
// act and assert
Assert.AreEqual("1=2&3=4", qs.ToString(HttpAction.Post));
}
示例10: Creating_from_map
public void Creating_from_map()
{
var args = new Dictionary<string, string>()
{
{ "foo", "bar" },
{ "abc", "123" },
};
var qs = new QueryString(args);
qs.ToString().ShouldBe("abc=123&foo=bar");
}
示例11: AssertEqual
private static void AssertEqual(QueryString expected, QueryString actual)
{
Assert.IsTrue(expected.Equals(actual), "Expected: " + expected + "\nActual: " + actual);
Assert.IsTrue(expected.Equals(QueryString.Parse(actual.ToString())), "After serializing and parsing actual, result changed.\n\nExpected: " + expected + "\nActual: " + QueryString.Parse(actual.ToString()));
Assert.IsTrue(QueryString.Parse(expected.ToString()).Equals(actual), "After serializing and parsing expected, result changed.\n\nExpected: " + QueryString.Parse(expected.ToString()) + "\nActual: " + actual);
Assert.IsTrue(QueryString.Parse(expected.ToString()).Equals(QueryString.Parse(actual.ToString())), "After serializing and parsing both, result changed.\n\nExpected: " + QueryString.Parse(expected.ToString()) + "\nActual: " + QueryString.Parse(actual.ToString()));
}
示例12: Canonicalize_flag_is_observed
public void Canonicalize_flag_is_observed()
{
var qs = new QueryString("search=start*&test=one two&tilde=~");
qs.ToString().ShouldBe("search=start*&test=one+two&tilde=%7E");
qs.ToString(canonical: true).ShouldBe("search=start%2A&test=one%20two&tilde=~");
}
示例13: Keys_with_no_values_are_ok
public void Keys_with_no_values_are_ok()
{
var qs = new QueryString(new Uri("https://foo.bar?foo=bar&baz=&three"));
qs.ToString().ShouldBe("baz=&foo=bar&three=");
}
示例14: Keys_are_sorted
public void Keys_are_sorted()
{
var qs = new QueryString(new Uri("https://foo.bar/?zulu=5&beta=foo&alpha=9"));
qs.ToString(canonical: true).ShouldBe("alpha=9&beta=foo&zulu=5");
}
示例15: Keys_and_value_case_is_preserved
public void Keys_and_value_case_is_preserved()
{
var qs = new QueryString(new Uri("http://foo.bar/baz?TEST=foo&bar=BAZ"));
qs.ToString().ShouldBe("bar=BAZ&TEST=foo");
}