当前位置: 首页>>代码示例>>C#>>正文


C# IRestClient.BuildUri方法代码示例

本文整理汇总了C#中IRestClient.BuildUri方法的典型用法代码示例。如果您正苦于以下问题:C# IRestClient.BuildUri方法的具体用法?C# IRestClient.BuildUri怎么用?C# IRestClient.BuildUri使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在IRestClient的用法示例。


在下文中一共展示了IRestClient.BuildUri方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: CanPreAuthenticate

 /// <summary>
 /// Does the authentication module supports pre-authentication?
 /// </summary>
 /// <param name="client">Client executing this request</param>
 /// <param name="request">Request to authenticate</param>
 /// <param name="credentials">The credentials to be used for the authentication</param>
 /// <returns>true when the authentication module supports pre-authentication</returns>
 public bool CanPreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials)
 {
     var cred = credentials?.GetCredential(client.BuildUri(request, false), AuthenticationMethod);
     if (cred == null)
         return false;
     return true;
 }
开发者ID:evnik,项目名称:restsharp.portable,代码行数:14,代码来源:SimpleAuthenticator.cs

示例2: Authenticate

        /// <summary>
        /// Authenticates the specified client and request using Hawk authentication.
        /// </summary>
        /// <param name="client">The RestSharp client instance use to submit the request.</param>
        /// <param name="request">The RestSharp request to execute.</param>
        public void Authenticate(IRestClient client, IRestRequest request)
        {
            var uri = client.BuildUri(request);
            var portSuffix = uri.Port != 80 ? ":" + uri.Port : "";
            var host = uri.Host + portSuffix;
            var method = request.Method.ToString();

            var header = Hawk.GetAuthorizationHeader(host, method, uri, _credential);

            request.AddHeader("Authorization", "Hawk " + header);
        }
开发者ID:linkypi,项目名称:hawknet,代码行数:16,代码来源:HawkNetAuthenticator.cs

示例3: PreAuthenticate

 /// <summary>
 /// Modifies the request to ensure that the authentication requirements are met.
 /// </summary>
 /// <param name="client">Client executing this request</param>
 /// <param name="request">Request to authenticate</param>
 /// <param name="credentials">The credentials used for the authentication</param>
 /// <returns>The task the authentication is performed on</returns>
 public Task PreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials)
 {
     return Task.Factory.StartNew(() =>
     {
         if (credentials == null)
             throw new InvalidOperationException("The credentials must be set using the IRestClient.Credential property.");
         var cred = credentials.GetCredential(client.BuildUri(request, false), AuthenticationMethod);
         if (cred == null)
             throw new InvalidOperationException($"No credentials provided for the {AuthenticationMethod} authentication type.");
         request.AddParameter(_usernameKey, cred.UserName, _parameterType);
         request.AddParameter(_passwordKey, cred.Password, _parameterType);
     });
 }
开发者ID:evnik,项目名称:restsharp.portable,代码行数:20,代码来源:SimpleAuthenticator.cs

示例4: Authenticate

        public void Authenticate(IRestClient client, IRestRequest request)
        {
            var nonce = GetNonce();

            var url = client.BuildUri(request);

            request.AddParameter("nonce", nonce, ParameterType.GetOrPost);
            var @params = request.Parameters.Where(p => p.Type == ParameterType.GetOrPost)
                .Select(p => p.Name.UrlEncode() + "=" + p.Value.ToString().UrlEncode());

            var hmacSig = GenerateSignature(string.Join("&", @params.ToArray()), this.apiSecret);

            request.AddHeader("x-api-key", this.apiKey)
                   .AddHeader("x-api-sign", hmacSig);
        }
开发者ID:bitbandi,项目名称:MiningRigRentalsApi,代码行数:15,代码来源:ApiAuthenticator.cs

示例5: GenerateSignature

        private string GenerateSignature(IRestClient client, IRestRequest request)
        {
            var uri = client.BuildUri(request);
            var query = uri.Query;

            if (!string.IsNullOrEmpty(query))
                query = query.Substring(1);

            var encoding = new System.Text.ASCIIEncoding();
            var key = encoding.GetBytes(_apiKey);
            var myhmacsha256 = new HMACSHA256(key);
            var hashValue = myhmacsha256.ComputeHash(encoding.GetBytes(query));
            var hmac64 = Convert.ToBase64String(hashValue);
            return hmac64;
        }
开发者ID:ElijahGlover,项目名称:UnleashedApi,代码行数:15,代码来源:HmacSignatureAuthenticator.cs

示例6: Authenticate

        public void Authenticate(IRestClient client, IRestRequest request)
        {
            request.Credentials = new NetworkCredential(_user, _pass);

            // TODO: Figure out how to remove the if.. currently PUT does not work if the DigestAuthFixer is in place
            if (request.Method == Method.GET)
            {
                var url = client.BuildUri(request).ToString();
                var uri = new Uri(url);

                var digestAuthFixer = new DigestAuthFixer(client.BaseUrl, _user, _pass);
                digestAuthFixer.GrabResponse(uri.PathAndQuery);
                var digestHeader = digestAuthFixer.GetDigestHeader(uri.PathAndQuery);
                request.AddParameter("Authorization", digestHeader, ParameterType.HttpHeader);
            }
        }
开发者ID:rdeslonde,项目名称:Stormpath-SDK-CSharp,代码行数:16,代码来源:DigestAuthenticator.cs

示例7: Authenticate

        public void Authenticate(IRestClient client, IRestRequest request)
        {
            var nonce = GetNonce();

            var url = client.BuildUri(request);

            var body = string.Empty;

            var param = request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
            if( param != null )
                body = param.Value.ToString();

            var hmacSig = GenerateSignature(nonce, url.ToString(), body, this.apiSecret);

            request.AddHeader("ACCESS_KEY", this.apiKey)
                .AddHeader("ACCESS_NONCE", nonce)
                .AddHeader("ACCESS_SIGNATURE", hmacSig);
        }
开发者ID:aimeedonahue,项目名称:Coinbase,代码行数:18,代码来源:CoinbaseApiAuthenticator.cs

示例8: Authenticate

        public void Authenticate(IRestClient client, IRestRequest request)
        {
            var uri = client.BuildUri(request);
            var path = uri.AbsolutePath;

            if( path.EndsWith("/time") && path.Length <= 8 )
            {
                request.AddHeader("CB-VERSION", CoinbaseConstants.ApiVersionDate);
                return;
            }
            string timestamp = null;
            if( useTimeApi )
            {
                var timeReq = new RestRequest("/time", Method.GET)
                    {
                        JsonSerializer = new JsonNetSerializer(jsonSettings)
                    };

                var timeResp = client.Execute<CoinbaseResponse<Time>>(timeReq);
                timestamp = timeResp.Data.Data.Epoch.ToString();
            }
            else
            {
                timestamp = GetCurrentUnixTimestampSeconds().ToString(CultureInfo.InvariantCulture);
            }

            var method = request.Method.ToString().ToUpper(CultureInfo.InvariantCulture);

            var body = string.Empty;

            var param = request.Parameters.FirstOrDefault(p => p.Type == ParameterType.RequestBody);
            if (param != null && param?.Value?.ToString() != "null" && !string.IsNullOrWhiteSpace(param?.Value?.ToString()))
                body = param.Value.ToString();

            var hmacSig = GenerateSignature(timestamp, method, path, body, this.apiSecret);

            request.AddHeader("CB-ACCESS-KEY", this.apiKey)
                .AddHeader("CB-ACCESS-SIGN", hmacSig)
                .AddHeader("CB-ACCESS-TIMESTAMP", timestamp)
                .AddHeader("CB-VERSION", CoinbaseConstants.ApiVersionDate);
        }
开发者ID:destenson,项目名称:Coinbase,代码行数:41,代码来源:CoinbaseApiAuthenticator.cs

示例9: Authenticate

        public void Authenticate( IRestClient client, IRestRequest request )
        {
            var uri = client.BuildUri( request );

            string method = AdaptMethod( request.Method );

            var tokens = m_context.CreateAuthenticatedTokens(uri, method);

            var authQueryParameters = CreateAuthQueryString( tokens );

            string url = uri.ToString();

            // manually set the resource url to work around RestSharp not letting you add query parameters
            // once you've added a body to the HTTP request
            bool hasQueryParameters = url.IndexOf( '?' ) != -1;

            if( hasQueryParameters ) {
                request.Resource = uri.PathAndQuery;
                request.Resource += "&" + authQueryParameters;
                request.Parameters.Clear();
            } else {
                request.Resource += "?" + authQueryParameters;
            }
        }
开发者ID:Brightspace,项目名称:valence-sdk-dotnet-restsharp,代码行数:24,代码来源:ValenceAuthenticator.cs

示例10: PreAuthenticate

        /// <summary>
        /// Modifies the request to ensure that the authentication requirements are met.
        /// </summary>
        /// <param name="client">Client executing this request</param>
        /// <param name="request">Request to authenticate</param>
        /// <param name="credentials">The credentials used for the authentication</param>
        /// <returns>The task the authentication is performed on</returns>
        public Task PreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials)
        {
            if (credentials == null)
            {
                throw new InvalidOperationException("The credentials must be set using the IRestClient.Credential property.");
            }

            var cred = credentials.GetCredential(client.BuildUri(request, false), AuthenticationMethod);
            if (cred == null)
            {
                throw new InvalidOperationException($"No credentials provided for the {AuthenticationMethod} authentication type.");
            }

            request.Parameters.AddOrUpdate(new Parameter { Type = _parameterType, Name = _usernameKey, Value = cred.UserName, ValidateOnAdd = false });
            request.Parameters.AddOrUpdate(new Parameter { Type = _parameterType, Name = _passwordKey, Value = cred.Password, ValidateOnAdd = false });

#if USE_TASKEX
            return TaskEx.FromResult(0);
#else
            return Task.FromResult(0);
#endif
        }
开发者ID:yuleyule66,项目名称:restsharp.portable,代码行数:29,代码来源:SimpleAuthenticator.cs

示例11: AddOAuthData

        private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
        {
            var url = client.BuildUri(request, false).ToString();
            OAuthWebQueryInfo oauth;
            var method = request.Method.ToString();
            var parameters = new WebParameterCollection();

            // include all GET and POST parameters before generating the signature
            // according to the RFC 5849 - The OAuth 1.0 Protocol
            // http://tools.ietf.org/html/rfc5849#section-3.4.1
            // if this change causes trouble we need to introduce a flag indicating the specific OAuth implementation level,
            // or implement a seperate class for each OAuth version
            var useMultiPart = request.ContentCollectionMode == ContentCollectionMode.MultiPart
                               || (request.ContentCollectionMode == ContentCollectionMode.MultiPartForFileParameters
                                   && (client.DefaultParameters.GetFileParameters().Any() || request.Parameters.GetFileParameters().Any()));

            var requestParameters = client.MergeParameters(request).OtherParameters.AsEnumerable();
            var effectiveMethod = client.GetEffectiveHttpMethod(request);
            if (effectiveMethod == Method.GET)
            {
                requestParameters = requestParameters.Where(x => x.Type == ParameterType.GetOrPost || x.Type == ParameterType.QueryString);
                foreach (var p in requestParameters)
                {
                    parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Query));
                }
            }
            else if (!useMultiPart && effectiveMethod == Method.POST)
            {
                foreach (var p in requestParameters.Where(x => x.Type == ParameterType.QueryString))
                {
                    parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Query));
                }
                foreach (var p in requestParameters.Where(x => x.Type == ParameterType.GetOrPost))
                {
                    parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Post));
                }
            }
            else
            {
                // if we are sending a multipart request, only the "oauth_" parameters should be included in the signature
                foreach (var p in requestParameters.Where(p => p.Name.StartsWith("oauth_", StringComparison.Ordinal)))
                {
                    parameters.Add(new WebParameter(p.Name, p.Value.ToString(), WebParameterType.Internal));
                }
            }

            switch (Type)
            {
                case OAuthType.RequestToken:
                    workflow.RequestTokenUrl = url;
                    oauth = workflow.BuildRequestTokenInfo(method, parameters);
                    break;
                case OAuthType.AccessToken:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ClientAuthentication:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildClientAuthAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ProtectedResource:
                    oauth = workflow.BuildProtectedResourceInfo(method, parameters, url);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            switch (ParameterHandling)
            {
                case OAuthParameterHandling.HttpAuthorizationHeader:
                    parameters.Add("oauth_signature", oauth.Signature, WebParameterType.Internal);
                    request.AddHeader("Authorization", GetAuthorizationHeader(parameters));
                    break;
                case OAuthParameterHandling.UrlOrPostParameters:
                    parameters.Add("oauth_signature", oauth.Signature, WebParameterType.Internal);
                    foreach (var parameter in parameters.Where(
                        parameter => !string.IsNullOrEmpty(parameter.Name)
                                     && (parameter.Name.StartsWith("oauth_") || parameter.Name.StartsWith("x_auth_"))))
                    {
                        var v = parameter.Value;
                        v = Uri.UnescapeDataString(v.Replace('+', ' '));
                        request.AddOrUpdateParameter(parameter.Name, v);
                    }

                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:yuleyule66,项目名称:restsharp.portable,代码行数:89,代码来源:OAuth1Authenticator.cs

示例12: AddOAuthData

        private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
        {
            var url = client.BuildUri(request).ToString();

            OAuthWebQueryInfo oauth;
            var method = request.Method.ToString().ToUpperInvariant();

            var parameters = new WebParameterCollection();

            // for non-GET style requests make sure params are part of oauth signature
            if (request.Method != Method.GET && request.Method != Method.DELETE)
            {
                foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
                {
                    parameters.Add(new WebPair(p.Name, p.Value.ToString()));
                }
            }

            switch (Type)
            {
                case OAuthType.RequestToken:
                    workflow.RequestTokenUrl = url;
                    oauth = workflow.BuildRequestTokenInfo(method, parameters);
                    break;
                case OAuthType.AccessToken:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ClientAuthentication:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildClientAuthAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ProtectedResource:
                    oauth = workflow.BuildProtectedResourceInfo(method, parameters, url);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            switch (ParameterHandling)
            {
                case OAuthParameterHandling.HttpAuthorizationHeader:
                    parameters.Add("oauth_signature", oauth.Signature);
                    request.AddHeader("Authorization", GetAuthorizationHeader(parameters));
                    break;
                case OAuthParameterHandling.UrlOrPostParameters:
                    parameters.Add("oauth_signature", HttpUtility.UrlDecode(oauth.Signature));
                    foreach (var parameter in parameters)
                    {
                        request.AddParameter(parameter.Name, parameter.Value);
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:h4x00r,项目名称:extentions,代码行数:56,代码来源:OAuth1Authenticator.cs

示例13: GetMessageAddress

 /// <summary>
 /// Get the REST requests relative address (for HTTP request message)
 /// </summary>
 /// <param name="client">REST client</param>
 /// <param name="request">REST request</param>
 /// <returns>The relative request message URL</returns>
 protected virtual Uri GetMessageAddress(IRestClient client, IRestRequest request)
 {
     var fullUrl = client.BuildUri(request);
     var url = client.BuildUri(null, false).MakeRelativeUri(fullUrl);
     return url;
 }
开发者ID:yuleyule66,项目名称:restsharp.portable,代码行数:12,代码来源:WebRequestHttpClientFactory.cs

示例14: Authenticate

        public void Authenticate(IRestClient client, IRestRequest request)
        {
            var url = client.BuildUri(request).ToString();

            // add body xauth arguments
            var arguments = new Dictionary<string, object>();
            if (string.IsNullOrWhiteSpace(Token))
            {
                arguments.Add("x_auth_username", Username);
                arguments.Add("x_auth_mode", "client_auth");
                arguments.Add("x_auth_password", Password);

                foreach (var item in arguments)
                {
                    request.AddParameter(item.Key, item.Value);
                }
            }
            else
            {
                foreach (var parameter in request.Parameters)
                {
                    arguments.Add(parameter.Name, parameter.Value);
                }
            }

            var nonce = OAuthTools.GetNonce();
            var signatureMethod = "HMAC-SHA1";
            var timeStamp = OAuthTools.GetTimestamp();
            var version = "1.0";

            var oauthArguments = new Dictionary<string, string>();
            oauthArguments.Add("oauth_signature_method", signatureMethod);
            oauthArguments.Add("oauth_nonce", nonce);
            oauthArguments.Add("oauth_consumer_key", ConsumerKey);
            oauthArguments.Add("oauth_timestamp", timeStamp);
            oauthArguments.Add("oauth_version", version);
            if (!string.IsNullOrWhiteSpace(Token))
            {
                oauthArguments.Add("oauth_token", Token);
            }

            var mergedArguments = new Dictionary<string, object>(arguments);
            foreach (var item in oauthArguments)
            {
                mergedArguments.Add(item.Key, item.Value);
            }

            mergedArguments = mergedArguments.OrderBy(i => i.Key).ToDictionary(pair => pair.Key, pair => pair.Value);

            var signatureBase = String.Format("{0}&{1}&", Method.POST, OAuthTools.UrlEncodeRelaxed(url));
            foreach (var item in mergedArguments)
            {
                var encodedKey = OAuthTools.UrlEncodeRelaxed(item.Key);
                string encodedValue;
                if (item.Value != null)
                {
                    encodedValue = OAuthTools.UrlEncodeRelaxed(item.Value.ToString());
                }
                else
                {
                    encodedValue = string.Empty;
                }
                signatureBase += String.Format("{0}%3D{1}%26", encodedKey, encodedValue);
            }

            signatureBase = signatureBase.Substring(0, signatureBase.Length - 3);
            signatureBase = signatureBase.Replace("%40", "%2540"); // ugly hack for now...

            var signature = OAuthTools.GetSignature(signatureBase, ConsumerSecret, TokenSecret);

            // create authorization header
            var authHeader = "OAuth ";
            authHeader += string.Format("{0}=\"{1}\"", "oauth_signature", signature);

            foreach (var item in oauthArguments)
            {
                authHeader += string.Format(", {0}=\"{1}\"", item.Key, item.Value);
            }
            request.AddHeader("Authorization", authHeader);
        }
开发者ID:weiran,项目名称:Metropaper,代码行数:80,代码来源:XAuthAuthenticator.cs

示例15: AddOAuthData

        private void AddOAuthData(IRestClient client, IRestRequest request, OAuthWorkflow workflow)
        {
            var url = client.BuildUri(request).ToString();
            var queryStringStart = url.IndexOf('?');
            if (queryStringStart != -1)
                url = url.Substring(0, queryStringStart);

            OAuthWebQueryInfo oauth;
            var method = request.Method.ToString().ToUpperInvariant();

            var parameters = new WebParameterCollection();

            // include all GET and POST parameters before generating the signature
            // according to the RFC 5849 - The OAuth 1.0 Protocol
            // http://tools.ietf.org/html/rfc5849#section-3.4.1
            // if this change causes trouble we need to introduce a flag indicating the specific OAuth implementation level,
            // or implement a seperate class for each OAuth version
            foreach (var p in client.DefaultParameters.Where(p => p.Type == ParameterType.GetOrPost))
            {
                parameters.Add( new WebPair( p.Name, p.Value.ToString() ) );
            }
            foreach (var p in request.Parameters.Where(p => p.Type == ParameterType.GetOrPost))
            {
                parameters.Add(new WebPair(p.Name, p.Value.ToString()));
            }

            switch (Type)
            {
                case OAuthType.RequestToken:
                    workflow.RequestTokenUrl = url;
                    oauth = workflow.BuildRequestTokenInfo(method, parameters);
                    break;
                case OAuthType.AccessToken:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ClientAuthentication:
                    workflow.AccessTokenUrl = url;
                    oauth = workflow.BuildClientAuthAccessTokenInfo(method, parameters);
                    break;
                case OAuthType.ProtectedResource:
                    oauth = workflow.BuildProtectedResourceInfo(method, parameters, url);
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            switch (ParameterHandling)
            {
                case OAuthParameterHandling.HttpAuthorizationHeader:
                    parameters.Add("oauth_signature", oauth.Signature);
                    request.AddHeader("Authorization", GetAuthorizationHeader(parameters));
                    break;
                case OAuthParameterHandling.UrlOrPostParameters:
                    parameters.Add("oauth_signature", oauth.Signature);
                    foreach (var parameter in parameters.Where(parameter => !parameter.Name.IsNullOrBlank() && parameter.Name.StartsWith("oauth_")))
                    {
                        request.AddParameter(parameter.Name, HttpUtility.UrlDecode(parameter.Value));
                    }
                    break;
                default:
                    throw new ArgumentOutOfRangeException();
            }
        }
开发者ID:nicwise,项目名称:RestSharp,代码行数:64,代码来源:OAuth1Authenticator.cs


注:本文中的IRestClient.BuildUri方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。