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


C# UriBuilder.SetQueryparameter方法代碼示例

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


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

示例1: ExecuteFeed

        public override WebResponse ExecuteFeed(string feedURL, IProvider provider, Token connectionToken, TRANSPORT_METHOD transportMethod)
        {
            UriBuilder ub;

            /******** retrieve standard Fields ************/
            ub = new UriBuilder(feedURL);

            ub.SetQueryparameter(AccessTokenQueryParameterKey, connectionToken.AccessToken);
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ub.ToString());
            request.Method = transportMethod.ToString();

            //logger.LogContactsRequest(ub.ToString());
            WebResponse wr;
            try
            {
                logger.Debug("Executing " + feedURL + " using " + transportMethod.ToString());
                wr = (WebResponse)request.GetResponse();
                logger.Info("Successfully executed  " + feedURL + " using " + transportMethod.ToString());
            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex);
                throw new OAuthException(ErrorMessages.CustomFeedExecutionError(feedURL, null), ex);
            }

            return wr;
        }
開發者ID:tamilstreetboy,項目名稱:socialauth-net,代碼行數:27,代碼來源:OAuth2_0Server.cs

示例2: RequestForAccessToken

        public void RequestForAccessToken()
        {
            UriBuilder ub = new UriBuilder(provider.AccessTokenEndpoint);
            ub.SetQueryparameter("client_id", provider.Consumerkey);
            ub.SetQueryparameter("client_secret", provider.Consumersecret);
            ub.SetQueryparameter("code", connectionToken.Code);
            ub.SetQueryparameter("redirect_uri", connectionToken.ProviderCallbackUrl);
            ub.SetQueryparameter("grant_type", "authorization_code");
            //logger.LogAuthorizationRequest(ub.ToString());
            HttpWebRequest request = (HttpWebRequest)HttpWebRequest.Create(ub.ToString());

            string authToken = "";
            try
            {
                logger.Debug("Requesting Access Token at " + ub.ToString());
                using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
                using (Stream responseStream = webResponse.GetResponseStream())
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    authToken = reader.ReadToEnd();
                    HandleAccessTokenResponse(authToken);
                }

            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
                throw new OAuthException(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
            }
        }
開發者ID:ranade80,項目名稱:Authorization-Samples,代碼行數:30,代碼來源:OAuth2_0Server.cs

示例3: RequestForAccessToken

        public void RequestForAccessToken(TRANSPORT_METHOD method = TRANSPORT_METHOD.GET)
        {
            if (method != TRANSPORT_METHOD.GET && method != TRANSPORT_METHOD.POST)
                throw new OAuthException("Invalid Verb used for requesting AccessToken. Supported verbs are GET/POST.");

            UriBuilder ub = new UriBuilder(provider.AccessTokenEndpoint);
            //logger.LogAuthorizationRequest(ub.ToString());
            HttpWebRequest request;

            if (method == TRANSPORT_METHOD.POST)
            {
                request = (HttpWebRequest)WebRequest.Create(ub.ToString());
                string postData = "code=" + ConnectionToken.Code;
                postData += ("&client_id=" + provider.Consumerkey);
                postData += ("&client_secret=" + provider.Consumersecret);
                postData += ("&redirect_uri=" + ConnectionToken.ProviderCallbackUrl);
                postData += ("&grant_type=authorization_code");

                request.Method = "POST";
                byte[] byteArray = Encoding.UTF8.GetBytes(postData);
                // Set the ContentType property of the WebRequest.
                request.ContentType = "application/x-www-form-urlencoded";
                // Set the ContentLength property of the WebRequest.
                request.ContentLength = byteArray.Length;
                // Get the request stream.
                Stream dataStream = request.GetRequestStream();
                // Write the data to the request stream.
                dataStream.Write(byteArray, 0, byteArray.Length);
                // Close the Stream object.
                dataStream.Close();
                // Get the response.
            }
            else
            {
                ub.SetQueryparameter("client_id", provider.Consumerkey);
                ub.SetQueryparameter("client_secret", provider.Consumersecret);
                ub.SetQueryparameter("code", ConnectionToken.Code);
                ub.SetQueryparameter("redirect_uri", ConnectionToken.ProviderCallbackUrl);
                ub.SetQueryparameter("grant_type", "authorization_code");

                request = (HttpWebRequest)WebRequest.Create(ub.ToString());
                request.Method = "POST";
            }


            try
            {
                logger.Debug("Requesting Access Token at " + ub.ToString());
                using (HttpWebResponse webResponse = (HttpWebResponse)request.GetResponse())
                using (Stream responseStream = webResponse.GetResponseStream())
                using (StreamReader reader = new StreamReader(responseStream))
                {
                    string authToken = reader.ReadToEnd();
                    HandleAccessTokenResponse(authToken);
                }

            }
            catch (Exception ex)
            {
                logger.Error(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
                throw new OAuthException(ErrorMessages.AccessTokenRequestError(request.RequestUri.ToString(), new QueryParameters()), ex);
            }
        }
開發者ID:tamilstreetboy,項目名稱:socialauth-net,代碼行數:63,代碼來源:OAuth2_0Server.cs

示例4: LoginCallback

 internal static void LoginCallback(string response)
 {
     try
     {
         ((IProviderConnect)ProviderFactory.GetProvider(InProgressToken().Provider)).LoginCallback(Utility.GetQuerystringParameters(response),
                 SocialAuthUser.OnAuthneticationProcessCompleted);
     }
     catch (Exception ex)
     {
         //User has specified to redirect here upon error instead fo throwing an error
         if (!string.IsNullOrEmpty(SessionManager.ErrorURL))
         {
             UriBuilder errorUri = new UriBuilder(SessionManager.ErrorURL);
             errorUri.SetQueryparameter("error_message", ex.Message);
             errorUri.SetQueryparameter("error_type", ex.GetType().ToString());
             HttpContext.Current.Response.Redirect(errorUri.Uri.AbsoluteUri.ToString());
         }
         else
             throw;
     }
 }
開發者ID:fizikci,項目名稱:Cinar,代碼行數:21,代碼來源:SocialAuthUser.cs


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