locked
Response Status code 400:Bad Request because of posting data with large size (httpclient) RRS feed

  • Question

  • User-693336589 posted

    at my project (asp.net soap webservice) I'm sending a form contains a file and a string to a webservice method via httpclient right as below:

    using (FileStream fs = File.Open(FileFullPath, FileMode.Open, FileAccess.Read, FileShare.ReadWrite))
            {
                using (var client = new HttpClient(new HttpClientHandler { UseProxy = false, Proxy = null }))
                {
                    using (var formData = new MultipartFormDataContent())
                    {
                        client.Timeout = TimeSpan.FromMilliseconds(Timeout.Infinite);
                        //client.MaxResponseContentBufferSize = fs.Length;
    
                        HttpContent TokenContent = new StringContent(Token);
                        HttpContent fileStreamContent = new StreamContent(fs);
    
                        formData.Add(TokenContent, "Token");
                        formData.Add(fileStreamContent, Key, currentFile);
    
                        var response = await client.PostAsync(WebServiceOfServer, formData).ConfigureAwait(false);
    
                        // equivalent of pressing the submit button on the form
                        if (!response.IsSuccessStatusCode)
                        {
                            result = null;
                        }
                        else
                        {
                            result = response.Content.ReadAsStreamAsync().Result;
                            return true;
                        }
                    }
                }
            }

    But in sending files which have the size grearter than 2GB, the response status code is 400 with the BadRequest phrase reason. 
     And In the web.config I used this codes:

    <httpRuntime maxRequestLength="3145728" requestLengthDiskThreshold="3145728" targetFramework="4.5.1" requestValidationMode="2.0" executionTimeout="999999"/>

    and

    <requestLimits maxAllowedContentLength="3221225472"/>

    How can I solve my problem?

     

     

    Monday, July 10, 2017 6:44 AM

Answers

  • User1168443798 posted

    Hi parsasaei,

    Did you host your web service in IIS? If so, I think you hit IIS limitation that IIS could not transfer data larger than 2 GB.

    There is currently no way to send a request to IIS with a request body larger than this. ASP.NET limits incoming requests to a maximum of 2GB. Thus the suggested (and only) way to upload files larger than 2GB to ASP.NET is via splitting.

    # Please, share how to upload files larger then 2GB (without splitting) on IIS 8.0 using ASP.NET 4.5?

    https://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/3122276-please-share-how-to-upload-files-larger-then-2gb

    Best Regards,

    Edward

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 11, 2017 6:49 AM

All replies

  • User1168443798 posted

    Hi parsasaei,

    Did you host your web service in IIS? If so, I think you hit IIS limitation that IIS could not transfer data larger than 2 GB.

    There is currently no way to send a request to IIS with a request body larger than this. ASP.NET limits incoming requests to a maximum of 2GB. Thus the suggested (and only) way to upload files larger than 2GB to ASP.NET is via splitting.

    # Please, share how to upload files larger then 2GB (without splitting) on IIS 8.0 using ASP.NET 4.5?

    https://aspnet.uservoice.com/forums/41199-general-asp-net/suggestions/3122276-please-share-how-to-upload-files-larger-then-2gb

    Best Regards,

    Edward

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Tuesday, July 11, 2017 6:49 AM
  • User-693336589 posted

    Thank you so much.

    Wednesday, July 12, 2017 11:52 AM