Skip to content Skip to sidebar Skip to footer

Nodejs: Content Encoding Error

I have the following Node.js code: var net = require('net'); var sys=require('sys'); var reqHash={}; var resHash={}; var server = net.createServer( function(soc){ soc.on('data

Solution 1:

According to the documentation : http://nodejs.org/docs/v0.4.10/api/http.html#response.write

response.write takes string or buffer. If it is a string, it also takes an encoding, the default encoding is utf-8.

So the encoding problems comes from the fact that you give him a string in UTF-8 and your browser is set in to another encoding.

In this code you also don't write any header, the browser must guess if it is text/plain or text/html you are sending him.

Post a Comment for "Nodejs: Content Encoding Error"