I try to send large message json(with images) using HttpClient.PostAsJsonAsync from one side and try get data in Controller using Microsoft.AspNet.Mvc version="5.2.3".
When I send small messages everything is okey.
Move code details:
private async Task<HttpResponseMessage> Method<TRequest>(string url, TRequest request,
IEnumerable<KeyValuePair<string, string>> headers)
{
using (var client = new HttpClient(_httpClientHandlerFactory.CreateHandler()))
{
client.DefaultRequestHeaders.Accept.Clear();
client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
client.DefaultRequestHeaders.CacheControl = new CacheControlHeaderValue { NoCache = true };
AddHeadersToClient(client, headers);
var response = await client.PostAsJsonAsync(url, request);
...
and on other side:
public class MyController: Controller
{
[HttpPost]
public ActionResult EmailBody(string siteShortName, string templateName, RequestAcceptType acceptType, [DynamicJson] dynamic model)
{
//Some logic
return View(viewPath, model);
}
...
And when sending message I get
Error during serialization or deserialization using the JSON JavaScriptSerializer. The length of the string exceeds the value set on the maxJsonLength property.
According article Can I set an unlimited length for maxJsonLength in web.config? I try to solve issue with different approches:
- added in web.config section
- try this code in controller method
- try to add something like this in Global.asax
And in all cases I have the same issue.