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

  • Question

  • 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); if (!response.IsSuccessStatusCode) { result = null; } else { result = response.Content.ReadAsStreamAsync().Result; return true; } } } }

    I set client.MaxResponseContentBufferSize=fs.Length.
    in sending files the size grearter than 
    2GB, the response status code is 400  BadRequest.. 
    "Buffering more than 2147483647 bytes is not supported.Actual value was 2380364657." that? And In the web.config :

    <httpRuntime maxRequestLength="3145728" executionTimeout="999999"/>
    <requestLimits maxAllowedContentLength="3221225472"/>

    How can increase this size or are there any better recommendation for do that?

    Saturday, July 8, 2017 11:24 AM

All replies

  • This more likely than not is intentional as we do this in some of our web applications in regards to limits to how large a file may be uploaded to our backend database. If this is the case you would need to contact the people who are responsible for the site.

    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Saturday, July 8, 2017 11:46 AM
  • You have no control of file upload size the site that controls the Web service will accept. The configuration information you are showing is for the client side configuration as to what it will accept when the Web service sends data to the client. Your application is  a client that consumed the Web service. 
    Saturday, July 8, 2017 12:15 PM
  • Hi ParsaSeai,

    Thank you for posting here.

    For your question, what is the type of your project? 

    If your question is more related to web service, you could post a new thread in WCF, ASMX and other Web Services forum for suitable support.

    Best Regards,


    MSDN Community Support
    Please remember to click "Mark as Answer" the responses that resolved your issue, and to click "Unmark as Answer" if not. This can be beneficial to other community members reading this thread. If you have any compliments or complaints to MSDN Support, feel free to contact

    Monday, July 10, 2017 3:00 AM
  • Thank you, ok I do it.
    Monday, July 10, 2017 6:46 AM