问题
I have simple Nancy self hosting C# project which deserializes data in NancyModule like this:
Post["/build"] = (something) => { var data = this.Bind<Brick>(); }
I am getting "Maximum JSON input length has been exceeded." when Request.Body.Length is close to 2MB. I would like to send tens of megabytes of data in the future and 2MB is just too low. Can I remove this limit?
回答1:
You can override the MaxJsonLength and the MaxRecursions. Basically I did a custom bootstrapper something like this:
public class CustomBootStrapper : DefaultNancyBootstrapper
{
protected override void ApplicationStartup(TinyIoCContainer container, IPipelines pipelines)
{
Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue;
Nancy.Json.JsonSettings.MaxRecursions = 100;
Nancy.Json.JsonSettings.RetainCasing = true;
base.ApplicationStartup(container, pipelines);
}
}
回答2:
For me Nancy didn't work all together even after applying below settings. As my data was really really huge.
Nancy.Json.JsonSettings.MaxJsonLength = int.MaxValue;
I ended up using Json.net (add via nuGet package)
JsonConvert.SerializeObject(data)
来源:https://stackoverflow.com/questions/45046242/nancy-maximum-json-length-exception-when-binding