Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6701223
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 26, 20262026-05-26T06:54:30+00:00 2026-05-26T06:54:30+00:00

I am having problems decoding UTF-8 strings in POST data when using the Node.JS

  • 0

I am having problems decoding UTF-8 strings in POST data when using the Node.JS web server.

See this complete testcase:

require("http").createServer(function(request, response) {

  if (request.method != "POST") {

    response.writeHead(200, {'Content-Type': 'text/html; charset=utf-8'});
    response.end('<html>'+
      '<head><meta http-equiv="content-type" content="text/html; charset=utf-8"></head>'+
      '<body>'+
      '<form method="post">'+
      '<input name="test" value="Grüße!"><input type="submit">'+
      '</form></body></html>');

  } else {

    console.log("CONTENT TYPE=",request.headers['content-type']);

    var body="";
    request.on('data', function (data) {
      body += data;
    });

    request.on('end', function () {
      console.log("POST BODY=",body);

      response.writeHead(200, {'Content-Type': 'text/plain; charset=utf-8'});
      response.end("POST DATA:\n"+body+"\n---\nUNESCAPED:\n"+unescape(body)+
        "\n---\nHARDCODED: Grüße!");
    });

  }

}).listen(11180);

This is a standalone web server that listens on port 11180 and sends a HTML page with a simple form that contains an input field with special characters. POSTing that form to the server will echo it’s contents in a plain text response.

My problem is that the special charactes are not being displayed properly neither on the console nor in the browser. This is what I see with both FireFox and IE:

POST DATA:
test=Gr%C3%BC%C3%9Fe%21
---
UNESCAPED:
test=GrüÃe!
---
HARDCODED: Grüße!

The last line is a hardcoded string Grüße! that should match the value of the input field (as to verify that it’s not a displaying problem). Obviously the POST data is not interpreted as UTF-8. The same problem happens when using require('querystring') to break the data into fields.

Any clue?

Using Node.JS v0.4.11 on Debian Linux 4, source code is saved in utf-8 charset

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-26T06:54:30+00:00Added an answer on May 26, 2026 at 6:54 am

    The üß UTF-8 characters are not found in the ascii charset, and are being represented by multiple ascii characters.

    According to http://www.w3.org/TR/html4/interact/forms.html#h-17.13.4.1

    The content type “application/x-www-form-urlencoded” is inefficient
    for sending large quantities of binary data or text containing
    non-ASCII characters
    . The content type “multipart/form-data” should be
    used for submitting forms that contain files, non-ASCII data, and
    binary data.

    Switching your enctype on the form to multipart <form method="post" enctype="multipart/form-data />" will correctly render the text as the UTF-8 characters. You then have to parse the multipart format. node-formidable seems to be the most popular lib for doing so.

    It’s probably much simpler to use decodeURIComponent() as you mentioned in a comment. Unescape does not handle multibyte characters, and instead represents each byte as its own character, hence the garbling you’re seeing. http://xkr.us/articles/javascript/encode-compare/

    You can also use buffers to change the encoding. Overkill in this case, but if you needed to:

    new Buffer(myString, 'ascii').toString('utf8');
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Im having problems building a query with the linq to sql data query expression
I'm having problems using textures that are larger than the OpenGL window or the
Having problems with this setup what im trying to do is like so. Steps
Having problems compiling this class. I'm working through a book on java and this
Having problems figuring this out. trying to do a rescue_from NoMethodError, :with => :try_some_options
Having problems with this. Let's say I have a parameter composed of a single
Having problems with the output of this formula: typedef struct { float t, Vx,
I'm having problems deciding on what is the best way is to handle and
Having problems with a small awk script, Im trying to choose the newest of
Having problems iterating. Problem has to do with const correctness, I think. I assume

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.