简体   繁体   English

发布请求体太大(参数对象中的字符串太大)

[英]Post request body too large (string in parameter object too large)

I have an MVC method: 我有一个MVC方法:

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. 在fileData中,我将byte[]从转换为string (UTF-8)的文件中放入,因此字符串可能很大。

Problem is: if the string is too large (somewhere above 15000 characters) the fileData parameter is null . 问题是:如果字符串太大fileData 15000个字符以上),则fileData参数为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? 如何让MVC接受更大的字符串,或者我是否需要事先以某种方式压缩字符串? 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? 也许是因为MVC使用JSON.NET而不是普通的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. 简单点是 - 你不要把字符串放入URL。 Simple like that. 很简单。 Add it as payload. 将其添加为有效负载。 URL's are ressource locators, not "Content carriers". URL是资源定位器,而不是“内容载体”。

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. 如果看起来Json没有正确编码发送方的某些字符,那就是当MVC控制器收到null时。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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