private static RestClient CreateRestClient(IRestRequest request) { var restClient = new RestClient(request.Url); if (request.UseNtlm) { restClient.Authenticator = new NtlmAuthenticator(); } return(restClient); }
public IRestResponse Execute(IRestRequest request) { var restClient = CreateRestClient(request); var restSharpRestRequest = ConvertRestRequest(request); var restSharpRestResponse = restClient.Execute(restSharpRestRequest); var restResponse = ConvertRestResponse(restSharpRestResponse); return(restResponse); }
public async Task <IRestResponse> ExecuteAsync(IRestRequest request, CancellationToken cancellationToken = default(CancellationToken)) { var restClient = CreateRestClient(request); var restSharpRestRequest = ConvertRestRequest(request); var restSharpRestResponse = await restClient.ExecuteTaskAsync(restSharpRestRequest, cancellationToken); var restResponse = ConvertRestResponse(restSharpRestResponse); return(restResponse); }
private static RestRequest ConvertRestRequest(IRestRequest request) { var method = ConvertMethod(request.HttpMethod); var restSharpRestRequest = new RestRequest { Method = method, Resource = string.Empty }; restSharpRestRequest.AddParameter("application/json", request.RequestBody, ParameterType.RequestBody); foreach (var requestHeader in request.Headers) { restSharpRestRequest.AddHeader(requestHeader.Name, requestHeader.Value); } return(restSharpRestRequest); }