你所做的应该对一次性工作很有帮助。如果你想要让它变得非常健壮,让它感觉像一流的 Flurl 功能,你可以遵循Flurl.Http 可扩展性模式并添加这些扩展方法:
public static class MultipartPutExtensions
{
public static Task<HttpResponseMessage> PutMultipartAsync(this IFlurlRequest request, Action<CapturedMultipartContent> buildContent, CancellationToken cancellationToken = default(CancellationToken))
{
var cmc = new CapturedMultipartContent(request.Settings);
buildContent(cmc);
return request.SendAsync(HttpMethod.Put, cmc, cancellationToken);
}
public static Task<HttpResponseMessage> PutMultipartAsync(this Url url, Action<CapturedMultipartContent> buildContent, CancellationToken cancellationToken = default(CancellationToken))
{
return new FlurlRequest(url).PutMultipartAsync(buildContent, cancellationToken);
}
public static Task<HttpResponseMessage> PutMultipartAsync(this string url, Action<CapturedMultipartContent> buildContent, CancellationToken cancellationToken = default(CancellationToken))
{
return new FlurlRequest(url).PutMultipartAsync(buildContent, cancellationToken);
}
}
PostMultipartAsync
这些是在实现之后直接建模的。