當前位置: 首頁>>代碼示例>>C#>>正文


C# UriBuilder.AppendQueryArgs方法代碼示例

本文整理匯總了C#中System.UriBuilder.AppendQueryArgs方法的典型用法代碼示例。如果您正苦於以下問題:C# UriBuilder.AppendQueryArgs方法的具體用法?C# UriBuilder.AppendQueryArgs怎麽用?C# UriBuilder.AppendQueryArgs使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在System.UriBuilder的用法示例。


在下文中一共展示了UriBuilder.AppendQueryArgs方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的C#代碼示例。

示例1: QueryAccessToken

        /// <summary>
        /// Obtains an access token given an authorization code and callback URL.
        /// </summary>
        /// <param name="returnUrl">
        /// The return url.
        /// </param>
        /// <param name="authorizationCode">
        /// The authorization code.
        /// </param>
        /// <returns>
        /// The access token.
        /// </returns>
        protected override string QueryAccessToken(Uri returnUrl, string authorizationCode)
        {
            var uriBuilder = new UriBuilder(AccessTokenServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("client_id", this.appId);
            args.Add("client_secret", this.appSecret);
            args.Add("redirect_uri", returnUrl.AbsoluteUri);
            args.Add("code", authorizationCode);

            uriBuilder.AppendQueryArgs(args);

            using (var webClient = new WebClient())
            {
                webClient.Headers.Add("Accept", "application/json");

                var text = webClient.UploadString(uriBuilder.Uri, string.Empty);
                if (string.IsNullOrEmpty(text))
                    return null;

                var data = JObject.Parse(text);
                return data["access_token"].Value<string>();
            }
        }
開發者ID:NorDroN,項目名稱:DotNetOpenAuth.AspNet.Extensions,代碼行數:37,代碼來源:GitHubClient.cs

示例2: GetServiceLoginUrl

		/// <summary>
		/// The get service login url.
		/// </summary>
		/// <param name="returnUrl">
		/// The return url.
		/// </param>
		/// <returns>An absolute URI.</returns>
		protected override Uri GetServiceLoginUrl(Uri returnUrl) {
			// Note: Facebook doesn't like us to url-encode the redirect_uri value
			var builder = new UriBuilder(AuthorizationEndpoint);
			builder.AppendQueryArgs(
				new Dictionary<string, string> {
					{ "client_id", this.appId },
					{ "redirect_uri", returnUrl.AbsoluteUri }
				});
			return builder.Uri;
		}
開發者ID:437072341,項目名稱:dotnetopenid,代碼行數:17,代碼來源:FacebookClient.cs

示例3: AddCallbackArgumentClearsPreviousArgument

 public void AddCallbackArgumentClearsPreviousArgument()
 {
     UriBuilder returnToWithArgs = new UriBuilder(this.returnTo);
     returnToWithArgs.AppendQueryArgs(new Dictionary<string, string> { { "p1", "v1" } });
     this.returnTo = returnToWithArgs.Uri;
     IAuthenticationRequest_Accessor authRequest = this.CreateAuthenticationRequest(this.claimedId, this.claimedId);
     authRequest.AddCallbackArguments("p1", "v2");
     var req = (SignedResponseRequest)authRequest.RedirectingResponse.OriginalMessage;
     NameValueCollection query = HttpUtility.ParseQueryString(req.ReturnTo.Query);
     Assert.AreEqual("v2", query["p1"]);
 }
開發者ID:jcp-xx,項目名稱:dotnetopenid,代碼行數:11,代碼來源:AuthenticationRequestTests.cs

示例4: GetServiceLoginUrl

		/// <summary>
		/// Gets the full url pointing to the login page for this client. The url should include the specified return url so that when the login completes, user is redirected back to that url.
		/// </summary>
		/// <param name="returnUrl">The return URL.</param>
		/// <returns>
		/// An absolute URL.
		/// </returns>
		protected override Uri GetServiceLoginUrl(Uri returnUrl) {
			var builder = new UriBuilder(AuthorizationEndpoint);
			builder.AppendQueryArgs(
				new Dictionary<string, string> {
					{ "client_id", this.appId },
					{ "scope", "wl.basic" },
					{ "response_type", "code" },
					{ "redirect_uri", returnUrl.AbsoluteUri },
				});

			return builder.Uri;
		}
開發者ID:raelyard,項目名稱:dotnetopenid,代碼行數:19,代碼來源:WindowsLiveClient.cs

示例5: GetServiceLoginUrl

        protected override Uri GetServiceLoginUrl(Uri returnUrl)
        {
            var builder = new UriBuilder(_authorizationEndpoint);
            builder.AppendQueryArgs(
                new Dictionary<string, string>
                {
                    {"response_type", "code"},
                    {"redirect_uri", returnUrl.AbsoluteUri},
                    {"scope", "https://www.googleapis.com/auth/userinfo.email"},
                    {"client_id", _clientId}
                });

            return builder.Uri;
        }
開發者ID:Teleopti,項目名稱:authbridge,代碼行數:14,代碼來源:GoogleOAuthClient.cs

示例6: GetServiceLoginUrl

 protected override Uri GetServiceLoginUrl(Uri returnUrl)
 {
     if (returnUrl == null) throw new ArgumentNullException("returnUrl");
     var builder = new UriBuilder("http://www.odnoklassniki.ru/oauth/authorize");
     var args = new Dictionary<string, string>
         {
             {"client_id", AppId},
             {"redirect_uri", returnUrl.AbsoluteUri},
             {"scope", ""},
             {"response_type", "code"}
         };
     builder.AppendQueryArgs(args);
     return builder.Uri;
 }
開發者ID:promorepublic,項目名稱:oauth,代碼行數:14,代碼來源:OkClient.cs

示例7: CreateHttpRequestInfo

		internal static HttpRequestMessage CreateHttpRequestInfo(HttpMethod method, IDictionary<string, string> fields) {
			var result = new HttpRequestMessage() { Method = method };
			var requestUri = new UriBuilder(DefaultUrlForHttpRequestInfo);
			if (method == HttpMethod.Post) {
				result.Content = new FormUrlEncodedContent(fields);
			} else if (method == HttpMethod.Get) {
				requestUri.AppendQueryArgs(fields);
			} else {
				throw new ArgumentOutOfRangeException("method", method, "Expected POST or GET");
			}

			result.RequestUri = requestUri.Uri;
			return result;
		}
開發者ID:Balamir,項目名稱:DotNetOpenAuth,代碼行數:14,代碼來源:MessagingTestBase.cs

示例8: GetServiceLoginUrl

        /// <summary>
        /// The get service login url.
        /// </summary>
        /// <param name="returnUrl">
        /// The return url.
        /// </param>
        /// <returns>An absolute URI.</returns>
        protected override Uri GetServiceLoginUrl(Uri returnUrl)
        {
            var builder = new UriBuilder(AuthorizationServiceEndpoint);

            var args = new Dictionary<string, string>();

            args.Add("client_id", this.appId);
            args.Add("response_type", "code");
            args.Add("redirect_uri", returnUrl.AbsoluteUri);

            builder.AppendQueryArgs(args);

            return builder.Uri;
        }
開發者ID:NorDroN,項目名稱:DotNetOpenAuth.AspNet.Extensions,代碼行數:21,代碼來源:InstagramClient.cs

示例9: GetServiceLoginUrl

 protected override Uri GetServiceLoginUrl(Uri returnUrl)
 {
     if (returnUrl == null) throw new ArgumentNullException("returnUrl");
     var builder = new UriBuilder("https://oauth.vk.com/authorize");
     var args = new Dictionary<string, string>
         {
             {"client_id", AppId},
             {"redirect_uri", NormalizeHexEncoding(returnUrl.AbsoluteUri)},
             {"display", "page"},
             {"response_type", "code"},
             {"scope", String.Join(",", Scopes)},
         };
     builder.AppendQueryArgs(args);
     return builder.Uri;
 }
開發者ID:promorepublic,項目名稱:oauth,代碼行數:15,代碼來源:VkClient.cs

示例10: GetServiceLoginUrl

 protected override Uri GetServiceLoginUrl(Uri returnUrl)
 {
     UriBuilder builder = new UriBuilder("https://oauth.live.com/authorize");
     Dictionary<string, string> args = new Dictionary<string, string>();
     args.Add("client_id", this.clientId);
     args.Add("scope", "wl.emails");
     args.Add("response_type", "code");
     #if DEBUG
     args.Add("redirect_uri", (new Uri(returnUrl.AbsoluteUri.Replace("localhost", "mstestdomain.com"))).AbsoluteUri);
     #else
     args.Add("redirect_uri", returnUrl.AbsoluteUri);
     #endif
     builder.AppendQueryArgs(args);
     return builder.Uri;
 }
開發者ID:mikalai-silivonik,項目名稱:bnh,代碼行數:15,代碼來源:WindowsLive.cs

示例11: GetReturnToArgumentAndNames

        public void GetReturnToArgumentAndNames()
        {
            UriBuilder returnToBuilder = new UriBuilder(this.response.ReturnTo);
            returnToBuilder.AppendQueryArgs(new Dictionary<string, string> { { "a", "b" } });
            this.request.ReturnTo = returnToBuilder.Uri;

            // First pretend that the return_to args were signed.
            this.response = new IndirectSignedResponse(this.request);
            this.response.ReturnToParametersSignatureValidated = true;
            Assert.AreEqual(1, this.response.GetReturnToParameterNames().Count());
            Assert.IsTrue(this.response.GetReturnToParameterNames().Contains("a"));
            Assert.AreEqual("b", this.response.GetReturnToArgument("a"));

            // Now simulate them NOT being signed.  They should still be visible at this level.
            this.response = new IndirectSignedResponse(this.request);
            this.response.ReturnToParametersSignatureValidated = false;
            Assert.AreEqual(1, this.response.GetReturnToParameterNames().Count());
            Assert.IsTrue(this.response.GetReturnToParameterNames().Contains("a"));
            Assert.AreEqual("b", this.response.GetReturnToArgument("a"));
        }
開發者ID:vrushalid,項目名稱:dotnetopenid,代碼行數:20,代碼來源:IndirectSignedResponseTests.cs

示例12: GetCallbackArguments

        public void GetCallbackArguments()
        {
            PositiveAssertionResponse assertion = this.GetPositiveAssertion();
            var rp = CreateRelyingParty();

            UriBuilder returnToBuilder = new UriBuilder(assertion.ReturnTo);
            returnToBuilder.AppendQueryArgs(new Dictionary<string, string> { { "a", "b" } });
            assertion.ReturnTo = returnToBuilder.Uri;
            var authResponse = new PositiveAuthenticationResponse(assertion, rp);

            // First pretend that the return_to args were signed.
            assertion.ReturnToParametersSignatureValidated = true;
            Assert.AreEqual(1, authResponse.GetCallbackArguments().Count);
            Assert.IsTrue(authResponse.GetCallbackArguments().ContainsKey("a"));
            Assert.AreEqual("b", authResponse.GetCallbackArgument("a"));

            // Now simulate them NOT being signed.
            assertion.ReturnToParametersSignatureValidated = false;
            Assert.AreEqual(0, authResponse.GetCallbackArguments().Count);
            Assert.IsFalse(authResponse.GetCallbackArguments().ContainsKey("a"));
            Assert.IsNull(authResponse.GetCallbackArgument("a"));
        }
開發者ID:jcp-xx,項目名稱:dotnetopenid,代碼行數:22,代碼來源:PositiveAuthenticationResponseTests.cs

示例13: GetUserData

        /// <summary>
        /// The get user data.
        /// </summary>
        /// <param name="accessToken">
        /// The access token.
        /// </param>
        /// <returns>A dictionary of profile data.</returns>
        protected override IDictionary<string, string> GetUserData(string accessToken)
        {
            var builder = new UriBuilder(GetUsersEndpoint);
            builder.AppendQueryArgs(
                new Dictionary<string, string> {
					{ "uid", _accessTokenResponse.user_id.ToString(CultureInfo.InvariantCulture) },
					{ "access_token", _accessTokenResponse.access_token }
				});


            using (var client = new WebClient { Encoding = Encoding.UTF8 })
            {
                string data = client.DownloadString(builder.Uri);
                if (string.IsNullOrEmpty(data))
                {
                    return null;
                }
                var response = JsonConvert.DeserializeObject<VkApiResponse>(data);
                if (response != null && response.response.Length == 1)
                {
                    var userData = new Dictionary<string, string>();
                    userData.AddItemIfNotEmpty("id", response.response[0].uid);
                    userData.AddItemIfNotEmpty("name", response.response[0].first_name + " " + response.response[0].last_name);

                    return userData;
                }
            }
            return new Dictionary<string, string>();
        }
開發者ID:odugen,項目名稱:Odugen.VkOAuth2Client,代碼行數:36,代碼來源:VkClient.cs

示例14: QueryAccessToken

        /// <summary>
        /// Obtains an access token given an authorization code and callback URL.
        /// </summary>
        /// <param name="returnUrl">
        /// The return url.
        /// </param>
        /// <param name="authorizationCode">
        /// The authorization code.
        /// </param>
        /// <returns>
        /// The access token.
        /// </returns>
        protected override string QueryAccessToken(Uri returnUrl, string authorizationCode)
        {
            // Note: Facebook doesn't like us to url-encode the redirect_uri value
            var builder = new UriBuilder(TokenEndpoint);
            builder.AppendQueryArgs(
                new Dictionary<string, string> {
					{ "client_id", _appId },
					{ "redirect_uri", NormalizeHexEncoding(returnUrl.AbsoluteUri) },
					{ "client_secret", _appSecret },
					{ "code", authorizationCode },
					{ "scope", "" },
				});

            using (var client = new WebClient())
            {
                string data = client.DownloadString(builder.Uri);
                if (string.IsNullOrEmpty(data))
                {
                    return null;
                }
                _accessTokenResponse = JsonConvert.DeserializeObject<VkAccessTokenResponse>(data);
                if (_accessTokenResponse != null)
                {
                    return _accessTokenResponse.access_token;
                }

                return string.Empty;
            }
        }
開發者ID:odugen,項目名稱:Odugen.VkOAuth2Client,代碼行數:41,代碼來源:VkClient.cs

示例15: QueryAccessToken

        private static string QueryAccessToken(string tokenEndpoint, string consumerKey, string consumerSecret, Uri returnUrl, string authorizationCode)
        {
            // Note: Facebook doesn't like us to url-encode the redirect_uri value
            var builder = new UriBuilder(tokenEndpoint);
            builder.AppendQueryArgs(
                new Dictionary<string, string> {
                    { "client_id", consumerKey },
                    { "redirect_uri", returnUrl.AbsoluteUri.NormalizeHexEncoding() },
                    { "client_secret", consumerSecret },
                    { "code", authorizationCode },
                    { "scope", "email" },
                });

            using (var client = new WebClient())
            {
                var data = client.DownloadString(builder.Uri);
                if (string.IsNullOrEmpty(data))
                {
                    return null;
                }

                var parsedQueryString = HttpUtility.ParseQueryString(data);
                return parsedQueryString["access_token"];
            }
        }
開發者ID:matthewbga,項目名稱:OAuthTestClient,代碼行數:25,代碼來源:MxOAuth2Client.cs


注:本文中的System.UriBuilder.AppendQueryArgs方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。