4

我有一个 MVC 方法:

public void PushFile([FromBody]FileTransport fileData)

类是:

public class FileTransport
    {
        public string fileData;
    }

在 fileData 我把byte[]从一个文件转换成一个string(UTF-8),所以字符串可以很大。

问题是:如果字符串太大(超过 15000 个字符),则fileData参数为null. 如果字符串不是那么大,则一切正常,参数也应如此。

如何允许 MVC 接受更大的字符串,或者我需要事先以某种方式压缩字符串?编辑:已经尝试过:

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

但不起作用。也许是因为 MVC 使用 JSON.NET 而不是普通的 JsonSerializer?

4

3 回答 3

3

您是否尝试增加请求的最大长度?

<system.web>
  <httpRuntime maxRequestLength="{REQUEST_LENGTH}"/>
<system.web>
于 2013-01-05T22:02:04.753 回答
0

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".

于 2013-01-05T23:10:22.363 回答
0

我发现它与内容长度无关。如果看起来 Json 没有正确编码发送方的某些字符,那就是 MVC 控制器收到 null 的时候。

于 2013-01-07T14:13:15.563 回答