【发布时间】:2016-08-11 19:13:28
【问题描述】:
我尝试使用 HttpClient.PostAsJsonAsync 从一侧发送大型消息 json(带图像),并尝试使用 Microsoft.AspNet.Mvc version="5.2.3" 在 Controller 中获取数据。
当我发送小消息时,一切正常。
移动代码详情:
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);
...
另一方面:
public class MyController: Controller
{
[HttpPost]
public ActionResult EmailBody(string siteShortName, string templateName, RequestAcceptType acceptType, [DynamicJson] dynamic model)
{
//Some logic
return View(viewPath, model);
}
...
发送消息时我得到
使用 JSON JavaScriptSerializer 进行序列化或反序列化时出错。字符串长度超过 maxJsonLength 属性设置的值。
根据文章Can I set an unlimited length for maxJsonLength in web.config?我尝试用不同的方法解决问题:
- 添加到 web.config section
- 在控制器方法中尝试this code
- 尝试在 Global.asax 中添加something like this
在所有情况下,我都有同样的问题。
【问题讨论】:
标签: c# asp.net json asp.net-mvc