1

I have a following controller

public class MyController : ApiController
{
   [HttpPost]
   public string LoadData(string currentState)
   {

   }
}

I post some data from browser with jQuery.post. The length of the state should be 29915 characters, but currentState variable has only 21621 characters. The end of the string is lost. I checked if browser sends all data to the server and it does. So the problem somewhere on the server.

Andrey M.
  • 3,688
  • 3
  • 33
  • 36
  • What do you set the content-type? – Aliostad Apr 20 '12 at 12:18
  • Firebug shows the request `Content-Type` header is `application/x-www-form-urlencoded; charset=UTF-8`. – Andrey M. Apr 20 '12 at 12:24
  • I just tested with 30K and worked fine. Does your string contains non-encoded stuff? – Aliostad Apr 20 '12 at 12:30
  • No, it is a valid JSON string. If I send that data directly to the generic handler (*.ashx), it work and I can deserialize the string. – Andrey M. Apr 20 '12 at 16:15
  • valid JSON?! This is supposed to be `application/x-www-form-urlencoded` not JSON. do you have `field=value&field=value`? – Aliostad Apr 20 '12 at 16:18
  • yes! it looks like productid=605&state=%7B%22CurVOI%22%3A-1%2C%22CurLI%22%3A-1%2C%22RgbCP%22%3Anull%2C%22CmykCP%22%3Anull%2C%22GrayscaleCP%22%3Anull%2C%22WW%22%3A318.0952%2C%22WH... long encoded string – Andrey M. Apr 20 '12 at 16:28
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/10332/discussion-between-andrey-m-and-aliostad) – Andrey M. Apr 20 '12 at 17:11

1 Answers1

0

Setting the ReadBufferSize helps:

protected void Application_Start(object sender, EventArgs e)
{
   GlobalConfiguration.Configuration.Formatters.FormUrlEncodedFormatter.ReadBufferSize = 256 * 1024; // 256 KB
}
Andrey M.
  • 3,688
  • 3
  • 33
  • 36