5 Replies Latest reply on May 7, 2008 4:35 AM by Peter.Coppens

    What is the proper way to set character encoding in an HTTPService request?

    JDK HM
      I'm trying to get an HTTPService object's request to have proper character encoding. If I do nothing, I get "null" inside a Java servlet when I call getCharacterEncoding() on the request object. If I do this to my Flex HTTPService:

      httpService.contentType = "application/x-www-form-urlencoded; charset=UTF-8";

      then I get a valid character encoding (UTF-8) in the Java servlet as I should. But the problem is that my HTTPService's POST parameters are no longer coming along with the request. If I drop the charset value and set this instead in Flex:

      httpService.contentType = "application/x-www-form-urlencoded";

      then I get my POST params in my servlet just fine, but of course, no charset info.

      (For completeness, I am also setting: httpService.method = "POST"; and httpService.resultFormat = "e4x"; as well as the URL.)

      How do I send charset info without interfering with the transmission of the POST params? This is a serious flaw for anyone doing UTF-8 content, because most servers are going to assume ISO-8859-1 if you don't send anything specific. It's interesting that Flex is actually encoding in UTF-8. I know, because I am currently working around the problem by intercepting the HTTP request in my servlet and forcing the character encoding to UTF-8 before binding the params. That's a lousy workaround, though.

      Hint to Flex 3 developers: It would be much more preferable to have a setCharacterEncoding method (or characterEncoding prop) on the Flex HTTPService.