public RestClientSettings() { DefaultFormat = ContentFormat.Json; DefaultHeaders = new Dictionary <string, object>(StringComparer.OrdinalIgnoreCase); RequestHandlers = new List <IRequestHandler>(); ResponseHandlers = new List <IRestResponseHandler>(); Serializers = new List <IContentSerializer> { new JsonContentSerializer(), new KeyValueContentSerializer(), new XmlContentSerializer() }; ContentTypeProvider = new DefaultContentTypeProvider(); ContentEncoding = Encoding.UTF8; DefaultCulture = CultureInfo.InvariantCulture; }
public static IRequestFileBuilder WithFileContent(this IRequestFileBuilder builder, string filePath) { if (!File.Exists(filePath)) { throw new FileNotFoundException($"Cannot find the file {filePath}.", filePath); } var provider = new DefaultContentTypeProvider(); var fileName = Path.GetFileName(filePath); var content = File.OpenRead(filePath); string contentType; if (provider.TryGetContentType(filePath, out contentType)) { builder = builder.WithContentType(contentType); } return(builder.WithFileName(fileName).WithContent(content)); }