本文整理汇总了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;
}
示例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();
}
示例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();
}