1

I have created a <form> that points to http://localhost:17099/Form/Subscribe and hosted in my website...

Every time I try to post North European characters, I get them like this:

enter image description here

That is me posting Bruno Alexandre å ø æ as the Name.

What do I need to do to get the correct encoded chars?

  • I have tried using the GetBytes() to figure it out if I could convert from one encoding to the other
  • I have tried using this trick
  • I have tried append accept-charset="ISO-8859-1" to the form

but nothing things to work...

If I check the Accept-Charset from the Current Request, I get:

ISO-8859-1,utf-8;q=0.7,*;q=0.3

If I play around with System.Text.Encoding I get this:

var name = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(model.Name);
string n = System.Text.Encoding.UTF8.GetString( name );

n will print as "Bruno Alexandre ? ? ?"

Drilling down and convert the string into bytes, if I send å æ ø, this is what I get:

var b = System.Text.Encoding.GetEncoding("iso-8859-1").GetBytes(model.Name);

b[0] = 63
b[1] = 32
b[2] = 63
b[3] = 32
b[4] = 63

witch results in "? ? ?"

Community
  • 1
  • 1
balexandre
  • 73,608
  • 45
  • 233
  • 342

1 Answers1

1

Maybe the form is not being posted with the correct content type; it should be:

application/x-www-form-urlencoded; charset=UTF-8

You can simple append this to your <form>

accept-charset="UTF-8" 
enctype="application/x-www-form-urlencoded; charset=UTF-8;"

so it will end up like:

<form method="post" 
      action="http://domain.com/subscribe" 
      accept-charset="UTF-8" 
      enctype="application/x-www-form-urlencoded; charset=UTF-8;">
balexandre
  • 73,608
  • 45
  • 233
  • 342
spender
  • 117,338
  • 33
  • 229
  • 351
  • appending `enctype="application/x-www-form-urlencoded; charset=UTF-8;"` to form generates the exact same problem :-/ – balexandre Nov 21 '11 at 13:00