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


C# IRestRequest.GetEffectiveHttpMethod方法代码示例

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


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

示例1: BuildUrl

 /// <summary>
 /// Build the full URL for a request
 /// </summary>
 /// <param name="client">The REST client that will execute the request</param>
 /// <param name="request">The REST request</param>
 /// <param name="withQuery">Should the resulting URL contain the query?</param>
 /// <returns>Resulting URL</returns>
 /// <remarks>
 /// The resulting URL is a combination of the REST client's BaseUrl and the REST requests
 /// Resource, where all URL segments are replaced and - optionally - the query parameters
 /// added.
 /// </remarks>
 public static Uri BuildUrl(this IRestClient client, IRestRequest request, bool withQuery = true)
 {
     var resource = request.Resource;
     foreach (var param in request.Parameters.Where(x => x.Type == ParameterType.UrlSegment))
     {
         var searchText = string.Format("{{{0}}}", param.Name);
         var replaceText = string.Format("{0}", param.Value);
         resource = resource.Replace(searchText, replaceText);
     }
     var urlBuilder = new UriBuilder(new Uri(client.BaseUrl, new Uri(resource, UriKind.RelativeOrAbsolute)));
     if (withQuery)
     {
         var queryString = new StringBuilder(urlBuilder.Query ?? string.Empty);
         var startsWithQuestionmark = queryString.ToString().StartsWith("?");
         foreach (var param in request.Parameters.Where(x => x.Type == ParameterType.QueryString))
         {
             if (queryString.Length > (startsWithQuestionmark ? 1 : 0))
                 queryString.Append("&");
             queryString.AppendFormat("{0}={1}", Uri.EscapeUriString(param.Name), Uri.EscapeUriString(string.Format("{0}", param.Value)));
         }
         if (request.GetEffectiveHttpMethod() == HttpMethod.Get)
         {
             var getOrPostParameters = request.GetGetOrPostParameters().ToList();
             foreach (var param in getOrPostParameters)
             {
                 if (queryString.Length > (startsWithQuestionmark ? 1 : 0))
                     queryString.Append("&");
                 queryString.AppendFormat("{0}={1}", Uri.EscapeUriString(param.Name), Uri.EscapeUriString(string.Format("{0}", param.Value)));
             }
         }
         urlBuilder.Query = queryString.ToString();
     }
     else
     {
         urlBuilder.Query = string.Empty;
     }
     return urlBuilder.Uri;
 }
开发者ID:changsunfung,项目名称:RestSharp.Portable,代码行数:50,代码来源:RestClientExtensions.cs

示例2: GetHttpMethod

 /// <summary>
 /// Returns the HTTP method for the request message.
 /// </summary>
 /// <param name="request">REST request</param>
 /// <returns>HTTP method</returns>
 protected virtual HttpMethod GetHttpMethod(IRestRequest request)
 {
     return request.GetEffectiveHttpMethod();
 }
开发者ID:changsunfung,项目名称:RestSharp.Portable,代码行数:9,代码来源:DefaultHttpClientFactory.cs

示例3: GetDigestHeader

        private string GetDigestHeader(IRestClient client, IRestRequest restRequest)
        {
            _nc = _nc + 1;

            var uri = client.BuildUrl(restRequest);
            var credential = _credentials.GetCredential(uri, "Digest");

            var pathAndQuery = uri.GetComponents(UriComponents.PathAndQuery, UriFormat.SafeUnescaped);

            var ha1 = CalculateMd5Hash(string.Format("{0}:{1}:{2}", credential.UserName, _realm, credential.Password));
            var ha2 = CalculateMd5Hash(string.Format("{0}:{1}", restRequest.GetEffectiveHttpMethod().Method, pathAndQuery));
            var digestResponse = CalculateMd5Hash(string.Format("{0}:{1}:{2:00000000}:{3}:{4}:{5}", ha1, _nonce, _nc, _cnonce, _qop, ha2));

            var result = new StringBuilder();
            result
                .AppendFormat("Digest username=\"{0}\"", credential.UserName)
                .AppendFormat(",realm=\"{0}\"", _realm)
                .AppendFormat(",nonce=\"{0}\"", _nonce)
                .AppendFormat(",uri=\"{0}\"", pathAndQuery)
                .AppendFormat(",algorithm=\"{0}\"", "MD5")
                .AppendFormat(",cnonce=\"{0}\"", _cnonce)
                .AppendFormat(",nc={0:D08}", _nc)
                .AppendFormat(",qop=\"{0}\"", _qop);
            if (!string.IsNullOrEmpty(_opaque))
                result
                    .AppendFormat(",opaque=\"{0}\"", _opaque);
            result
                .AppendFormat(",response=\"{0}\"", digestResponse);
            return result.ToString();
        }
开发者ID:changsunfung,项目名称:RestSharp.Portable,代码行数:30,代码来源:HttpDigestAuthenticator.cs


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