当前位置: 首页>>代码示例>>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;未经允许,请勿转载。