2 Replies Latest reply on Jan 4, 2017 10:04 AM by Hao Yong

    is undertow do not support multi bytes character in request form data?

    Hao Yong Newbie

      I'm using wildfly-10.1.0.Final, it's undertow module is undertow-core-1.4.0.Final.

       

      The browser send a form request (enctype=”multipart/form-data”) with chinese character in form data, but on the server side, this message is garbled.

       

      I notice that: undertow parse formdata in method - io.undertow.server.handlers.form.FormEncodedDataDefinition$FormEncodedDataParser.doParse(final StreamSourceChannel channel)

      first, read bytes to a byte buffer, and then, deal with the data byte by byte in a state machine. If current byte is part of param value, then append it to a StringBuilder to cache it. But, the program append the byte as a char:

      builder.append((char) n);

      when recover the message ,the program invoke:

      data.add(name, builder.toString());

      so, the multi bytes character split to parts.

       

      is undertow do not support multi bytes character in request form data?

        • 1. Re: is undertow do not support multi bytes character in request form data?
          Tomaz Cerar Master

          It does support it, but you need to specify charset for your request

          1 of 1 people found this helpful
          • 2. Re: is undertow do not support multi bytes character in request form data?
            Hao Yong Newbie

            Thank you Tomaz !

            I am sorry that the problem's root cause is something else. After debug i found that it's a jquery ajax post request like this:

            $.ajax({

                    type: 'POST',

                    contentType: 'application/x-www-form-urlencoded;charset=UTF-8',

                    data: 'dataType=1&keyType=2&key=你好&interfaceId=1',

                    url: 'testctrl/formdata',

                    success: function (data) {alert("success")},

                    error:function() {alert("error")},

                    dataType:'xml'

                });

            there is chinese characters in data( key=你好 ). I add content type and specified charset to UTF-8 already, but the problem is still on.

             

            Now i can resolve this problem in two way:

              1. converting chinese character with encodeURI :  data: 'dataType=1&keyType=2&key='+encodeURI('你好') + '&interfaceId=1'

              2. change data to json format :  data: {dataType:1,keyType:2,key:"你好",interfaceId:1}

             

            But i still want to know if there is another way to compatible with chinese characters in data without encodeURI .  I found that the charset do take place when FormDataParser creating in FormEncodedDataDefinition, but the charset seems only work for urlencoded string.