/// <summary>Initializes a new instance of the <see cref="APIClientAttribute" /> class.</summary> public APIClient(APIEnvironment environment) { if (environment == null) { throw new ArgumentNullException(nameof(environment)); } Environment = environment; }
/// <summary>Initializes a new instance of the <see cref="APIClientAttribute" /> class with a specific handler.</summary> /// <param name="handler">The <see cref="System.Net.Http.HttpMessageHandler" /> responsible for processing the HTTP response messages.</param> /// <param name="disposeHandler"> /// <see langword="true" /> if the inner handler should be disposed of by Dispose(), <see langword="false" /> if you intend to reuse the inner handler.</param> public APIClient(APIEnvironment environment, HttpMessageHandler handler, bool disposeHandler) : base(handler, disposeHandler) { if (environment == null) { throw new ArgumentNullException(nameof(environment)); } Environment = environment; }
public void Prepare(HttpRequestMessage request, APIEnvironment environment, IParameterInfo body) { if (body == null) { return; } if (body.Data is Stream stream) { request.Content = new StreamContent(stream); } else { var result = environment.ContentNegotiator .Negotiate(body.Type, request, environment.MediaTypeFormatters); var writer = result.Formatter; request.Content = new ObjectContent(body.Type, body.Data, writer); } }