/// <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; }
protected override HttpRequestMessage BuildMessage(IRestRequest request) { // Create message content var content = new MultipartFormDataContent(); foreach (var param in request.Parameters) { var file = param.Value as FileParameter; if (file != null) { var contentPart = new ByteArrayContent(file.Content); contentPart.Headers.Add("Content-Type", file.ContentType); content.Add(contentPart, param.Key, file.Name); } else { var contentPart = new StringContent(param.Value.ToString()); content.Add(contentPart, param.Key); } } // Build message var message = new HttpRequestMessage(request.Verb.ToHttpMethod(), request.Command) { Content = content }; return message; }
/// <summary> /// Create the client /// </summary> /// <param name="client">The REST client that wants to create the HTTP client</param> /// <param name="request">The REST request for which the HTTP client is created</param> /// <returns>A new HttpClient object</returns> /// <remarks> /// The DefaultHttpClientFactory contains some helpful protected methods that helps gathering /// the data required for a proper configuration of the HttpClient. /// </remarks> public virtual IHttpClient CreateClient(IRestClient client, IRestRequest request) { var headers = new GenericHttpHeaders(); var httpClient = new DefaultHttpClient(this, headers) { BaseAddress = GetBaseAddress(client) }; if (client.Timeout.HasValue) { httpClient.Timeout = client.Timeout.Value; } var proxy = GetProxy(client); if (proxy != null) { httpClient.Proxy = new RequestProxyWrapper(proxy); } var cookieContainer = GetCookies(client, request); if (cookieContainer != null) { httpClient.CookieContainer = cookieContainer; } if (_setCredentials) { var credentials = client.Credentials; if (credentials != null) { httpClient.Credentials = credentials; } } return httpClient; }
/// <summary> /// Merge parameters from client and request /// </summary> /// <param name="client">The REST client that will execute the request</param> /// <param name="request">The REST request</param> /// <returns>A list of merged parameters</returns> public static IList<Parameter> MergeParameters([CanBeNull] this IRestClient client, IRestRequest request) { var parameters = new List<Parameter>(); // Add default parameters first if (client != null) { parameters.AddRange(client.DefaultParameters); } // Now the client parameters if (request != null) { parameters.AddRange(request.Parameters); } var comparer = new ParameterComparer(client, request); var result = parameters .Select((p, i) => new { Parameter = p, Index = i }) // Group by parameter type/name .GroupBy(x => x.Parameter, comparer) // Select only the last of all duplicate parameters .Select(x => new { x.Last().Parameter, x.First().Index }) // Sort by appearance .OrderBy(x => x.Index) .Select(x => x.Parameter) .ToList(); return result; }
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); }
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(); }
private void PopulateRoutes(IRestRequest request) { foreach (var route in _definition.Routes) { request.AddParameter("routes", route.ToString()); } }
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); }
/// <summary> /// Handles the specified request by applying all current filters. /// </summary> /// <param name="request">The REST API request that will be used to instantiate this state instance.</param> /// <returns></returns> public IRestResponse Handle(IRestRequest request) { var redirectable = request as RedirectableRestRequest; string originalBaseUrl = null; IRestResponse result = null; foreach (var filter in filters) { filter.Handle((IRestClient)this, request); } // Prevent parallel execution issues (per instance) since this is a destructive property pattern lock (_lock) { if (redirectable != null && redirectable.BaseUrl != this.BaseUrl && !string.IsNullOrEmpty(redirectable.BaseUrl)) { originalBaseUrl = this.BaseUrl; this.BaseUrl = redirectable.BaseUrl; } result = this.Execute(request); if (originalBaseUrl != null) { this.BaseUrl = originalBaseUrl; } } return result; }
private void ReplaceAcceptWithJson(IRestRequest restRequest) { foreach (var parameter in restRequest.Parameters.Where(p => p.Name == "Accept")) { parameter.Value = "application/json"; } }
/// <summary> /// Override the method which does the actually call against the Tictail API using REST client /// These are both 3-party and should be working just fine /// </summary> /// <param name="request">RestRequst, is not needed for this</param> /// <returns>A RestResonse object</returns> protected override IRestResponse RestRequest(IRestRequest request) { IRestResponse response = new RestResponse(); response.StatusCode = StatusCode; response.ResponseStatus = ResponseStatus; response.Content = Content; if (ResponseHeaders == null) { return response; } foreach (var header in ResponseHeaders) { response.Headers.Add(new Parameter() { Name = header.Key, Value = header.Value, Type = ParameterType.HttpHeader }); } return response; }
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; }
private BillingConnectorResponse PostApi(string segment, IRestRequest request) { try { log.InfoFormat("Invoking billing API on {0} with segment {1}", configuration.Url, segment); request.AddHeader("apikey", configuration.ApiKey); var response = client.Post(request); if (response.StatusCode == HttpStatusCode.OK) return new BillingConnectorResponse(true); var failureMessage = string.Format( "Call to billing API return non OK status code. The status code was {0}. The response status code was {1}. The error description is {2}", response.StatusCode, response.ResponseStatus, response.ErrorMessage); log.ErrorFormat(failureMessage); } catch (Exception e) { log.ErrorFormat("Failed to invoke billing API on {0} because {1}", configuration.Url, e); } return new BillingConnectorResponse(false); }
public BaseRestService(IRestHandler restHandler, IFormat formator, IRestRequest restRequest) { _restHandler = restHandler; _formator = formator; _restRequest = restRequest; Initialize(); }
public void Authenticate(IRestClient client, IRestRequest request) { DateTime signingDate = DateTime.UtcNow; SetContentMd5(request); SetContentSha256(request); SetHostHeader(client, request); SetDateHeader(request, signingDate); SortedDictionary<string, string> headersToSign = GetHeadersToSign(request); string signedHeaders = GetSignedHeaders(headersToSign); string region = Regions.GetRegion(client.BaseUrl.Host); string canonicalRequest = GetCanonicalRequest(client, request, headersToSign); byte[] canonicalRequestBytes = System.Text.Encoding.UTF8.GetBytes(canonicalRequest); string canonicalRequestHash = BytesToHex(ComputeSha256(canonicalRequestBytes)); string stringToSign = GetStringToSign(region, canonicalRequestHash, signingDate); byte[] signingKey = GenerateSigningKey(region, signingDate); byte[] stringToSignBytes = System.Text.Encoding.UTF8.GetBytes(stringToSign); byte[] signatureBytes = SignHmac(signingKey, stringToSignBytes); string signature = BytesToHex(signatureBytes); string authorization = GetAuthorizationHeader(signedHeaders, signature, signingDate, region); request.AddHeader("Authorization", authorization); }
/// <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; }
protected override HttpRequestMessage BuildMessage(IRestRequest request) { var internalRequest = request as PostContentRestRequest; if (internalRequest == null) throw new ArgumentException($"'{nameof(request)}' is not the PostContentRestRequest."); // build url with parameters bool fistParam = true; var cmdBuilder = new StringBuilder(request.Command); if (request.Parameters != null) { foreach (var param in request.Parameters) { var divider = fistParam ? "?" : "&"; cmdBuilder.Append($"{divider}{param.Key}={param.Value.ToString()}"); fistParam = false; } } // Create POST request var message = new HttpRequestMessage(request.Verb.ToHttpMethod(), cmdBuilder.ToString()) { Content = new StreamContent(internalRequest.Content) }; return message; }
/// <summary> /// Gets the content 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 GetContent([CanBeNull] this IRestClient client, IRestRequest request) { HttpContent content; var parameters = client.MergeParameters(request); var collectionMode = request?.ContentCollectionMode ?? ContentCollectionMode.MultiPartForFileParameters; if (collectionMode != ContentCollectionMode.BasicContent) { var fileParameters = parameters.GetFileParameters().ToList(); if (collectionMode == ContentCollectionMode.MultiPart || fileParameters.Count != 0) { content = client.GetMultiPartContent(request); } else { content = client.GetBasicContent(request); } } else { content = client.GetBasicContent(request); } if (content == null) return null; return new DefaultHttpContent(content); }
public void Authenticate(IRestClient client, IRestRequest request) { if(!request.Parameters.Any(p => p.Name.Equals("Authorization", StringComparison.OrdinalIgnoreCase))) { request.AddParameter("Authorization", "SuTToken " + _token, ParameterType.HttpHeader); } }
private async Task<IRestResponse> ExecuteInternal(IRestRequest request, string httpMethod, Func<IHttp, string, Task<HttpResponse>> getResponse) { AuthenticateIfNeeded(this, request); // add Accept header based on registered deserializers var accepts = string.Join(", ", AcceptTypes.ToArray()); this.AddDefaultParameter("Accept", accepts, ParameterType.HttpHeader); IRestResponse response = new RestResponse(); try { var http = HttpFactory.Create(); ConfigureHttp(request, http); //TODO: Add support for Proxy //ConfigureProxy(http); response = ConvertToRestResponse(request, await getResponse(http, httpMethod)); response.Request = request; response.Request.IncreaseNumAttempts(); } catch (Exception ex) { response.ResponseStatus = ResponseStatus.Error; response.ErrorMessage = ex.Message; response.ErrorException = ex; } return response; }
public override void Authenticate(IRestClient client, IRestRequest request) { if (!string.IsNullOrWhiteSpace(AccessToken)) { request.AddHeader("authorization", string.Format("bearer {0}", AccessToken)); } }
public When(IRestClient client, IRestRequest request, IRestResponse response) { this.client = client; this.request = request; this.response = response; data = new Object(); }
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; }
internal void Apply(IRestRequest request) { _ops.ForEach((op) => { request.AddQueryParameter(op.Type.ToString(), op.Value); }); }
public override void AddFilter(IRestRequest request) { base.AddFilter(request); if (MinimumId != null) { request.AddParameter("min_id", MinimumId, ParameterType.GetOrPost); } if (MaximumId != null) { request.AddParameter("max_id", MaximumId, ParameterType.GetOrPost); } if (Name != null) { request.AddParameter("name", Name, ParameterType.GetOrPost); } if (ParentId != null) { request.AddParameter("parent_id", ParentId, ParameterType.GetOrPost); } if (IsVisible != null) { request.AddParameter("is_visible", IsVisible, ParameterType.GetOrPost); } }
/// <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); } } }
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); }
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))); }
private void ApplyOptions(IRestRequest request, bool isGet) { if (_asanaOptionsApplier != null) { _asanaOptionsApplier.ApplyOptions(request, true); } }
/// <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); }
public virtual Task <IRestResponse> ExecuteTaskAsync( IRestRequest request, CancellationToken token, Method httpMethod ) => ExecuteAsync(request, httpMethod, token);
/// <summary> /// Allows for extending response processing for <see cref="ApiClient"/> generated code. /// </summary> /// <param name="request">The RestSharp request object</param> /// <param name="response">The RestSharp response object</param> partial void InterceptResponse(IRestRequest request, IRestResponse response);
public QueryRouterService GetSingleObject(string schemaId, string objectId) { _request = new RestRequest($"/single/{objectId}", Method.POST); _request.AddHeader("SCHEMA_ID", schemaId); return(this); }
public QueryRouterService GetAllObjectsFromSchema(string schemaId) { _request = new RestRequest("schema", Method.GET); _request.AddHeader("SCHEMA_ID", schemaId); return(this); }
/// <summary> /// Executes the specified request and downloads the response data /// </summary> /// <param name="request">Request to execute</param> /// <returns>Response data</returns> // ReSharper disable once ParameterOnlyUsedForPreconditionCheck.Global public byte[] DownloadData(IRestRequest request) => DownloadData(request, false);
/// <summary> /// Execute a manual REST request /// </summary> /// <param name="request">The RestRequest to execute (will use client credentials)</param> public virtual IRestResponse Execute(IRestRequest request) { return(_client.Execute(request)); }
private T Execute <T>(IRestRequest request) where T : new() { var response = Execute <IRestResponse <T> >(request, client => client.Execute <T>); return(response.Data); }
private IRestResponse Execute(IRestRequest request) { var response = Execute <IRestResponse>(request, client => client.Execute); return(response); }
public AccountResponseCollection List() { IRestRequest request = this.CreateRequest(this.Resource, Method.GET); return(this.ExecuteRequest <AccountResponseCollection>(request).Data); }
/// <summary> /// Allows for extending request processing for <see cref="ApiClient"/> generated code. /// </summary> /// <param name="request">The RestSharp request object</param> partial void InterceptRequest(IRestRequest request);
static void Configure(string baseUrl, IRestRequest request) { rClient = new RestClient(baseUrl); req = request; }
/// <summary> /// Sets 'x-amz-date' http header. /// </summary> /// <param name="request">Instantiated request object</param> /// <param name="signingDate">Date for signature to be signed</param> private void SetDateHeader(IRestRequest request, DateTime signingDate) { request.AddHeader("x-amz-date", signingDate.ToString("yyyyMMddTHHmmssZ")); }
static void AddParameters(IRestRequest request) { request.AddParameter("foo", "bar"); request.AddParameter("a name with spaces", "somedata"); }
/// <summary> /// Set 'Host' http header. /// </summary> /// <param name="request">Instantiated request object</param> /// <param name="hostUrl">Host url</param> private void SetHostHeader(IRestRequest request, string hostUrl) { request.AddHeader("Host", hostUrl); }
protected void AddAuthorizationHeader(IRestRequest request, string apiKey) { request?.AddHeader(AuthenticationHeaderName, string.Format(AuthenticationHeaderValueFormat, apiKey)); }
protected IRestResponse SendRequest(IRestRequest request) { return(_client.Execute(request)); }
/// <summary> /// Reconcile ExchangeCommand parameters with supplied and default values, and populate them into the IRestRequest /// </summary> /// <param name="request">Unpopulated IRestRequest</param> /// <param name="command">Reference Command</param> /// <param name="pair">Trading Pair</param> /// <param name="values">Explicitly supplied parameter values</param> private static void PopulateCommandParameters(IRestRequest request, IExchangeCommand command, TradingPair pair, IDictionary <StandardParameter, string> values) { foreach (var param in command.Parameters) { var parameter = param.Value; string value; switch (parameter.StandardParameterIdentifier) { case StandardParameter.Price: case StandardParameter.Amount: case StandardParameter.Id: case StandardParameter.Timestamp: case StandardParameter.Limit: value = values[parameter.StandardParameterIdentifier]; break; case StandardParameter.Base: value = pair.BaseCurrency.ToString(); break; case StandardParameter.Counter: value = pair.CounterCurrency.ToString(); break; case StandardParameter.Currency: value = pair.BaseCurrency.ToString(); break; case StandardParameter.CurrencyFullName: value = pair.BaseCurrency.GetDescription(); break; case StandardParameter.Pair: value = pair.ToString(); break; case StandardParameter.UnixTimestamp: value = DateTime.UtcNow.AddHours(-1).ToUnixTime().ToStringInvariant(); break; case StandardParameter.None: value = parameter.DefaultValue; break; default: value = string.Empty; break; } var parameterType = ParameterType.GetOrPost; if (parameter.ParameterMethod == ParameterMethod.Url) { parameterType = ParameterType.UrlSegment; } else if (parameter.ParameterMethod == ParameterMethod.QueryString) { parameterType = ParameterType.QueryString; } request.AddParameter(parameter.ExchangeParameterName, value, parameterType); } }
public RestRequestAsyncHandle ExecuteAsync <T>(IRestRequest request, Action <IRestResponse <T> > callback) where T : new() { request.DateFormat = string.IsNullOrEmpty(request.DateFormat) ? DefaultDateParameterFormat : request.DateFormat; return(client.ExecuteAsync <T>(request, callback)); }
IRestResponse <T> IEdsmRestClient.Execute <T>(IRestRequest request) => restClient.Execute <T>(request);
/// <summary> /// Clones the current state instance. /// </summary> /// <param name="request">The REST API request used to create this state instance.</param> /// <param name="response">The REST API response used to create this state instance.</param> /// <param name="client">The REST API client used to create this state instance.</param> /// <returns>A cloned instance of the current state instance.</returns> protected abstract GedcomxApplicationState Clone(IRestRequest request, IRestResponse response, IFilterableRestClient client);
public static Task <IRestResponse> ExecuteAsync(this RestClient client, IRestRequest request) { return(client.ExecuteAsync(request, r => r)); }
private void ConfigureHttp(IRestRequest request, IHttp http) { http.AlwaysMultipartFormData = request.AlwaysMultipartFormData; http.UseDefaultCredentials = request.UseDefaultCredentials; http.ResponseWriter = request.ResponseWriter; http.CookieContainer = CookieContainer; // move RestClient.DefaultParameters into Request.Parameters foreach (var p in DefaultParameters) { if (request.Parameters.Any(p2 => p2.Name == p.Name && p2.Type == p.Type)) { continue; } request.AddParameter(p); } // Add Accept header based on registered deserializers if none has been set by the caller. if (request.Parameters.All(p2 => p2.Name.ToLowerInvariant() != "accept")) { var accepts = string.Join(", ", AcceptTypes.ToArray()); request.AddParameter("Accept", accepts, ParameterType.HttpHeader); } http.Url = BuildUri(request); http.PreAuthenticate = PreAuthenticate; var userAgent = UserAgent ?? http.UserAgent; http.UserAgent = userAgent.HasValue() ? userAgent : "RestSharp/" + version; var timeout = request.Timeout > 0 ? request.Timeout : Timeout; if (timeout > 0) { http.Timeout = timeout; } var readWriteTimeout = request.ReadWriteTimeout > 0 ? request.ReadWriteTimeout : ReadWriteTimeout; if (readWriteTimeout > 0) { http.ReadWriteTimeout = readWriteTimeout; } #if !SILVERLIGHT http.FollowRedirects = FollowRedirects; #endif #if FRAMEWORK if (ClientCertificates != null) { http.ClientCertificates = ClientCertificates; } http.MaxRedirects = MaxRedirects; #endif if (request.Credentials != null) { http.Credentials = request.Credentials; } var headers = from p in request.Parameters where p.Type == ParameterType.HttpHeader select new HttpHeader { Name = p.Name, Value = p.Value.ToString() }; foreach (var header in headers) { http.Headers.Add(header); } var cookies = from p in request.Parameters where p.Type == ParameterType.Cookie select new HttpCookie { Name = p.Name, Value = p.Value.ToString() }; foreach (var cookie in cookies) { http.Cookies.Add(cookie); } var @params = from p in request.Parameters where p.Type == ParameterType.GetOrPost && p.Value != null select new HttpParameter { Name = p.Name, Value = p.Value.ToString() }; foreach (var parameter in @params) { http.Parameters.Add(parameter); } foreach (var file in request.Files) { http.Files.Add(new HttpFile { Name = file.Name, ContentType = file.ContentType, Writer = file.Writer, FileName = file.FileName, ContentLength = file.ContentLength }); } var body = (from p in request.Parameters where p.Type == ParameterType.RequestBody select p).FirstOrDefault(); if (body != null) { object val = body.Value; if (val is byte[]) { http.RequestBodyBytes = (byte[])val; } else { http.RequestBody = body.Value.ToString(); } http.RequestContentType = body.Name; } #if FRAMEWORK ConfigureProxy(http); #endif }
/// <summary> /// Initializes a new instance of the <see cref="RestRequestEventArgs"/> class. /// </summary> /// <param name="request">The request object.</param> public RestRequestEventArgs(IRestRequest request) { Request = request; }
public Uri BuildUri(IRestRequest request) => restClient.BuildUri(request);
public Task PreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials) { return(Authenticate(client, request)); }
/// <summary> /// Gets the content for a request. /// </summary> /// <param name="request">The <see cref="IRestRequest"/> to get the content for.</param> /// <returns>The <see cref="IHttpContent"/> for the <paramref name="request"/></returns> protected override IHttpContent GetContent(IRestRequest request) { return(RestClientExtensions.GetContent(this, request)); }
/// <summary> /// Deletes an order with the given Id. /// </summary> /// <param name="orderId">The order object's Id.</param> public async Task DeleteAsync(long orderId) { IRestRequest req = RequestEngine.CreateRequest("orders/{0}.json".FormatWith(orderId), Method.DELETE); await RequestEngine.ExecuteRequestAsync(_RestClient, req); }
public OrientCommandException(IRestRequest request, IRestResponse response, T input) : base(GetMessage(input), GetInnerException(request, response)) { Request = request; Response = response; Input = input; }
/// <summary> /// Opens a closed order. /// </summary> /// <param name="id">The order's id.</param> public async Task OpenAsync(long id) { IRestRequest req = RequestEngine.CreateRequest("orders/{0}/open.json".FormatWith(id), Method.POST); await RequestEngine.ExecuteRequestAsync(_RestClient, req); }
public bool CanPreAuthenticate(IRestClient client, IRestRequest request, ICredentials credentials) { return(true); }