本文整理汇总了C#中System.Uri.GetQueryParameters方法的典型用法代码示例。如果您正苦于以下问题:C# Uri.GetQueryParameters方法的具体用法?C# Uri.GetQueryParameters怎么用?C# Uri.GetQueryParameters使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类System.Uri
的用法示例。
在下文中一共展示了Uri.GetQueryParameters方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GetQueryParameters_ShouldReturnEmptyDictionaryForNoParameters
public void GetQueryParameters_ShouldReturnEmptyDictionaryForNoParameters()
{
var uri = new Uri("http://www.foo.bar/index.htm");
var result = uri.GetQueryParameters();
Assert.That(result.Count(), Is.EqualTo(0));
}
示例2: GetQueryParameters_ShouldReturnOneElementDictionaryForSingleParameter
public void GetQueryParameters_ShouldReturnOneElementDictionaryForSingleParameter()
{
var uri = new Uri("http://www.foo.bar/index.htm?foo=bar");
var result = uri.GetQueryParameters();
Assert.That(result.Count(), Is.EqualTo(1));
Assert.That(result.First().Key, Is.EqualTo("foo"));
Assert.That(result.First().Value, Is.EqualTo("bar"));
}
示例3: GetQueryParameters_ShouldHandleBrokenParameter
public void GetQueryParameters_ShouldHandleBrokenParameter()
{
var uri = new Uri("http://www.foo.bar/index.htm?foo=bar&bar=foo&broken");
var result = uri.GetQueryParameters();
Assert.That(result.Count(), Is.EqualTo(3));
Assert.That(result.First().Key, Is.EqualTo("foo"));
Assert.That(result.First().Value, Is.EqualTo("bar"));
Assert.That(result.ElementAt(1).Key, Is.EqualTo("bar"));
Assert.That(result.ElementAt(1).Value, Is.EqualTo("foo"));
Assert.That(result.Last().Key, Is.EqualTo("broken"));
Assert.That(result.Last().Value, Is.EqualTo(""));
}
示例4: Authorize
public void Authorize(Uri verificationUri)
{
if (verificationUri == null) throw new ArgumentNullException("verificationUri");
var verifier = verificationUri.GetQueryParameters()["oauth_verifier"];
var entity = GetAdapterSettings();
if (string.IsNullOrEmpty(verifier) || entity.OAuthRequestToken == null)
{
throw new AuthorizationException();
}
var accessToken = PhotoAdapter.GetOAuthAccessToken(entity.OAuthRequestToken, verifier);
entity.OAuthRequestToken = null;
entity.OAuthAccessToken = accessToken;
UpdateAdapterSettings(entity);
}
示例5: RequestOAuthToken
/// <summary>
/// Requests an <see cref="OAuth2Token"/> using the <see cref="Uri"/> that was requested after the Authorization by the user.
/// </summary>
/// <param name="responseUri">The complete <see cref="Uri"/> of the request after Authorization.</param>
/// <param name="clientSecret">The api secret of the app.</param>
/// <returns>An <see cref="OAuth2Token"/> that can be used to access protected resources.</returns>
public OAuth2Token RequestOAuthToken(Uri responseUri, string clientSecret)
{
if (responseUri == null) throw new ArgumentNullException("responseUri");
if (_soundCloudClient.RedirectUri == null)
{
var baseUrl = new Uri(responseUri.GetLeftPart(UriPartial.Authority));
_soundCloudClient.RedirectUri = new Uri(baseUrl, responseUri.AbsolutePath);
}
var queryPairs = responseUri.GetQueryParameters();
if (queryPairs.ContainsKey("error"))
{
throw new ArgumentException(string.Format("Error: {0}, Description: {1}", queryPairs["error"], queryPairs["error_description"]));
}
return _soundCloudClient.OAuthToken = _soundCloudClient.RequestOAuthToken(queryPairs["code"], clientSecret);
}