【问题标题】:Is there a way to push large files to a remote server using System.Net.Http.HttpClient有没有办法使用 System.Net.Http.HttpClient 将大文件推送到远程服务器
【发布时间】:2014-06-05 16:29:35
【问题描述】:

我正在尝试使用 System.Net.Http.HttpClient 将 50 MB 文件推送到远程服务器:

private async void Transfer_Product_Upgrade_Package(object sender, RoutedEventArgs e)
{
    await UploadFileAsync();
}

async Task UploadFileAsync()
{
    string filename = @"C:\AccountView\AccountViewPublish\ProductPackage.zip";

    Uri uri = new Uri("http://localhost:3748/api/UploadProductPackage/5");

    using (var stream = File.OpenRead(filename))
    {
        var client = new HttpClient();
        var response = await client.PostAsync(uri, new StreamContent(stream));
        response.EnsureSuccessStatusCode();
    }
}

我什至没有访问目标服务器就收到了这个响应:

响应状态码不表示成功:413(请求实体太大)。

使用完全相同的代码传输较小的文件就好了。

有没有办法处理更大的文件?

【问题讨论】:

    标签: c# asp.net dotnet-httpclient


    【解决方案1】:

    默认的最大 IIS 7 上传文件大小约为 28mb。对于更大的文件大小,您需要使用 WebConfig 配置 IIS 7 以允许更大的大小:

    <system.webServer>
      <security>
        <requestFiltering>
          <requestLimits maxAllowedContentLength="2147483648" />
        </requestFiltering>
      </security>
    </system.webServer>
    

    另外,ASP.NET 运行时有额外的限制。您可以在此处更改:

    <system.web>
      <httpRuntime maxRequestLength="2097152" />
    </system.web>
    

    查看此link 了解更多信息。

    【讨论】:

      猜你喜欢
      • 2018-03-12
      • 2010-09-06
      • 1970-01-01
      • 1970-01-01
      • 2013-03-10
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-11-14
      相关资源
      最近更新 更多