locked
problem with post data RRS feed

  • Question

  • User-1301771973 posted

    i want post data from a html page to an aspx page,and i must set requestEncoding as utf-8.

    how could i post data use charset as utf-8 and get true resoult.i want post chinese character.my html page is:

    __________________________________________________________________________________________________________

    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
    <html>
    <head>
    <title></title>
    <meta name="GENERATOR" content="Microsoft Visual Studio .NET 7.1">
    <meta name=ProgId content=VisualStudio.HTML>
    <meta name=Originator content="Microsoft Visual Studio .NET 7.1">
    </head>
    <body>
     <div align=center>
      <form method=post action="search.aspx" target=_blank>
       <input name="button" type=submit value="提交" > 
       <input name="sendvalue" type=hidden value="猫猫,恭喜拉!我是Julian">
      </form>
     </div>
    </body>
    </html>

    __________________________________________________________________________________________________________

     and i request data use

    __________________________________________________________________________________________________________

       if(!Page.IsPostBack)
       {
        byte [] str = System.Text.Encoding.UTF8.GetBytes(Request.Form["sendvalue"]);
        Response.Write(System.Text.Encoding.GetEncoding("gb2312").GetString(str).ToString()); 
       }
    __________________________________________________________________________________________________________

    Friday, July 27, 2007 4:00 AM

Answers

  • User1622957740 posted

    Why do you need all this codepage conversion?

    If you're using UTF-8 encoding you should just be able to read the Form data and write it back out without any sort of conversion - it's Unicode after all. .NET will do all the appropriate Unicode encoding decoding from the Request/Response encoding. Just make sure both your request and response encoding in web.config is set to UTF-8 (which is the default anyway).

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 28, 2007 3:46 PM

All replies

  • User1622957740 posted

    Why do you need all this codepage conversion?

    If you're using UTF-8 encoding you should just be able to read the Form data and write it back out without any sort of conversion - it's Unicode after all. .NET will do all the appropriate Unicode encoding decoding from the Request/Response encoding. Just make sure both your request and response encoding in web.config is set to UTF-8 (which is the default anyway).

     

     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Saturday, July 28, 2007 3:46 PM
  • User-1301771973 posted

    [:D]thank you for your reply.but i realy couldn't get correctly reoult when  request and respone set encoding as utf-8.

    but  i solved this problem using javascript encoding and cshap decoding get the correctly resoult 

    Monday, July 30, 2007 6:50 AM