本文整理汇总了C#中IRestRequest类的典型用法代码示例。如果您正苦于以下问题:C# IRestRequest类的具体用法?C# IRestRequest怎么用?C# IRestRequest使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IRestRequest类属于命名空间,在下文中一共展示了IRestRequest类的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;
}
示例2: IsCanProcessRequest
protected override bool IsCanProcessRequest(IRestRequest request)
{
return (request.Verb == HttpVerb.Post || request.Verb == HttpVerb.Put)
&& request.GetType() == typeof(RestRequest)
&& request.Parameters != null
&& request.Parameters.Any(p => p.Value is FileParameter);
}
示例3: ApplyOptions
public void ApplyOptions(IRestRequest request, bool isGet)
{
if (_options == null)
{
return;
}
ApplyOptionsStrategy applyOptionsStrategy = isGet
? (ApplyOptionsStrategy)
new GetApplyOptionsStrategy(request, _options)
: new PostApplyOptionsStrategy(request, _options);
if (_options.Pretty)
{
applyOptionsStrategy.ApplyPretty();
}
if (_options.Fields != null && _options.Fields.Count > 0)
{
applyOptionsStrategy.ApplyFields();
}
if (_options.Expand != null && _options.Expand.Count > 0)
{
applyOptionsStrategy.ApplyExpand();
}
applyOptionsStrategy.Finish();
}
示例4: PopulateSubEntities
private void PopulateSubEntities(IRestRequest request)
{
new LobImageFilePopulator(_definition.Front, "front").Populate(request);
new LobImageFilePopulator(_definition.Back, "back").Populate(request);
if (_definition.Data != null) new DataPopulator(_definition.Data).Populate(request);
if (_definition.MetaData != null) new MetaDataPopulator(_definition.MetaData).Populate(request);
}
示例5: ReplaceAcceptWithJson
private void ReplaceAcceptWithJson(IRestRequest restRequest)
{
foreach (var parameter in restRequest.Parameters.Where(p => p.Name == "Accept"))
{
parameter.Value = "application/json";
}
}
示例6: RestException
public RestException(IRestRequest request, IRestResponse response)
: base(string.Format("The endpoint at '{0}' didn't respond with 'OK'. Instead it was '{1}'.",
response.ResponseUri, response.StatusCode), response.ErrorException??new Exception(response.Content))
{
Request = request;
Response = response;
}
示例7: BaseRestService
public BaseRestService(IRestHandler restHandler, IFormat formator, IRestRequest restRequest)
{
_restHandler = restHandler;
_formator = formator;
_restRequest = restRequest;
Initialize();
}
示例8: GetBasicContent
/// <summary>
/// Gets the basic content (without files) for a request
/// </summary>
/// <param name="client">The REST client that will execute the request</param>
/// <param name="request">REST request to get the content for</param>
/// <returns>The HTTP content to be sent</returns>
internal static IHttpContent GetBasicContent([CanBeNull] this IRestClient client, IRestRequest request)
{
IHttpContent content;
var parameters = client.MergeParameters(request);
var body = parameters.FirstOrDefault(x => x.Type == ParameterType.RequestBody);
if (body != null)
{
content = request.GetBodyContent(body);
}
else
{
if (client.GetEffectiveHttpMethod(request) == Method.POST)
{
var getOrPostParameters = parameters.GetGetOrPostParameters().ToList();
if (getOrPostParameters.Count != 0)
{
content = new PostParametersContent(getOrPostParameters);
}
else
{
content = null;
}
}
else
{
content = null;
}
}
return content;
}
示例9: Authenticate
/// <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>
public void Authenticate(IRestClient client, IRestRequest request)
{
// only add the Authorization parameter if it hasn't been added by a previous Execute
if (request.Parameters.Any(p => p.Name != null && p.Name.Equals("Authorization", StringComparison.OrdinalIgnoreCase)))
return;
request.AddParameter("Authorization", this._authHeader, ParameterType.HttpHeader);
}
示例10: Build
public HttpRequestMessage Build(IRestRequest request, IDictionary<string, string> persistentHeaders)
{
if (!this.IsCanProcessRequest(request))
return null;
HttpRequestMessage message = this.BuildMessage(request);
// Set headers
message.Headers.Add("Accept", "application/json");
// Add persistent headers
if (request.Headers != null) {
foreach (var header in request.Headers)
this.AddHeader(header.Key, header.Value, message);
}
// Add message headers
if (persistentHeaders != null) {
foreach (var header in persistentHeaders)
if (request.Headers == null || !request.Headers.ContainsKey(header.Key))
this.AddHeader(header.Key, header.Value, message);
}
return message;
}
示例11: Apply
internal void Apply(IRestRequest request)
{
_ops.ForEach((op) =>
{
request.AddQueryParameter(op.Type.ToString(), op.Value);
});
}
示例12: Authenticate
public void Authenticate(IRestClient client, IRestRequest request)
{
if (request.Parameters.Exists(p => p.Name.Equals("Cookie", StringComparison.InvariantCultureIgnoreCase)))
return;
request.AddParameter("cookie", _authHeader, ParameterType.HttpHeader);
}
示例13: BuildDebugUri
/// <summary>
/// Assembles URL to call based on parameters, method and resource
/// </summary>
/// <param name="client">RestClient performing the execution</param>
/// <param name="request">RestRequest to execute</param>
/// <returns>Assembled System.Uri</returns>
/// <remarks>
/// RestClient's BuildUri purposefully leaves off the parameters from the uri it builds when the request
/// is a POST, PUT, or PATCH. This extension method aims to undo this feature for debugging reasons
/// </remarks>
public static Uri BuildDebugUri(this IRestClient client, IRestRequest request)
{
var uri = client.BuildUri(request);
if (request.Method != Method.POST &&
request.Method != Method.PUT &&
request.Method != Method.PATCH)
{
return uri;
}
else
{
var queryParameters = from p in request.Parameters
where p.Type == ParameterType.GetOrPost
select string.Format("{0}={1}", Uri.EscapeDataString(p.Name), Uri.EscapeDataString(p.Value.ToString()));
if (!queryParameters.Any())
{
return uri;
}
else
{
var path = uri.OriginalString.TrimEnd('/');
var query = string.Join("&", queryParameters);
return new Uri(path + "?" + query);
}
}
}
示例14: ApplyOptions
private void ApplyOptions(IRestRequest request, bool isGet)
{
if (_asanaOptionsApplier != null)
{
_asanaOptionsApplier.ApplyOptions(request, true);
}
}
示例15: LogRequest
private void LogRequest(RestClient restClient, IRestRequest request, IRestResponse response, long durationMs)
{
var requestToLog = new
{
resource = request.Resource,
// Parameters are custom anonymous objects in order to have the parameter type as a nice string
// otherwise it will just show the enum value
parameters = request.Parameters.Select(parameter => new
{
name = parameter.Name,
value = parameter.Value,
type = parameter.Type.ToString()
}),
// ToString() here to have the method as a nice string otherwise it will just show the enum value
method = request.Method.ToString(),
// This will generate the actual Uri used in the request
uri = restClient.BuildUri(request),
};
var responseToLog = new
{
statusCode = response.StatusCode,
content = response.Content,
headers = response.Headers,
// The Uri that actually responded (could be different from the requestUri if a redirection occurred)
responseUri = response.ResponseUri,
errorMessage = response.ErrorMessage,
};
Trace.Write(string.Format("Request completed in {0} ms, Request: {1}, Response: {2}",
durationMs,
JsonConvert.SerializeObject(requestToLog),
JsonConvert.SerializeObject(responseToLog)));
}