简体   繁体   中英

Post request body too large (string in parameter object too large)

I have an MVC method:

public void PushFile([FromBody]FileTransport fileData)

Class is:

public class FileTransport
    {
        public string fileData;
    }

In fileData I put byte[] from a file converted into a string (UTF-8), so the string can be large.

Problem is: if the string is too large (somewhere above 15000 characters) the fileData parameter is null . If the string is not that large, everything works fine and the parameter is as it should be.

How can I allow MVC to accept larger strings, or do I need to compress the string somehow beforehand? EDIT: Already tried:

<system.web.extensions>
<scripting>
  <webServices>
    <jsonSerialization maxJsonLength="2147483644"/>
  </webServices>
</scripting>
</system.web.extensions>

But does not work. Maybe because MVC uses JSON.NET instead of the normal JsonSerializer?

Did you try to increase max length of the request?

<system.web>
  <httpRuntime maxRequestLength="{REQUEST_LENGTH}"/>
<system.web>

Simple Point is - you dont put the string into the URL. Simple like that. Add it as payload. URL's are ressource locators, not "Content carriers".

I figured out it had nothing to do with content length. If seems like the Json does not encode properly with some characters on the sender's side, that's when MVC controller recieved null.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM