4

I wrote an MVC action to receive a post from a service. My problem is that the service is posting multipart data with wrong encoding.

Let me give an example:

  • The service will post the "á" for the form field "text".
  • I see (using Wireshark), that the byte written on the packet is 225, which is the right byte for "á" in ISO-8859-1 .
  • I do Request.Form["text"] and actually get a strange (different) char.

I believe this is cause by .NET attempting to convert the value 225 to a unicode char, when converting to string using the utf-8 encoding, but couldn't, as 225 isn't valid for utf-8.

So my question is: Is there a way to override the parsing of those bytes to string?

tereško
  • 58,060
  • 25
  • 98
  • 150
Israel Lot
  • 653
  • 1
  • 9
  • 16
  • This may be relevant http://stackoverflow.com/questions/708915/detecting-the-character-encoding-of-an-http-post-request – m0s Jul 25 '12 at 03:38

1 Answers1

1

You could try to add a HttpModule and try to overwrite the ContentEncoding property of the Request object. Though I'm not sure this will work.

It's possible to set the default encoding in Web.Config's GlobalizationSection. The setting is called RequestEncoding and is taken to effect only if the HTTP request of your service does not contain a ContentType header. See http://msdn.microsoft.com/en-us/library/system.web.configuration.globalizationsection.requestencoding.aspx

You can further use inside Web.config to set the above setting only to a specific directory / MVC controller.

fan711
  • 716
  • 3
  • 13