I’m using nodejs http.get method to post datas to a php
But the php’s charset is not UTF-8, it’s ISO-8859-9 (turkish)
So post data’s not being inserted to database in correct way,
this is my node js file :
var data="ğüşıöç ĞÜŞİÖÇ"
var postdata="isim="+encodeURIComponent(data)+"";
var options2 =
{
host: "localhost",
port: 80,
path: "/bbb.php",
method: 'POST',
headers:{"Host":"localhost","Content-Length": postdata.length,'Content-Type': 'application/x-www-form-urlencoded'}
};
var post_req = http.get(options2, function (res)
{
var responseBody='';
res.on('data', function (d) { responseBody += d; });
res.on('end', function (d)
{
sys.print(responseBody);
});
}).on('error', function (e) {sys.print(e.message);});
post_req.write(postdata);
post_req.end();
and this is php file :
<?
header('Content-type: text/html; charset=ISO-8859-9');
$dbbaglanti=mysql_connect("localhost", "root", "");
mysql_select_db("db");
mysql_query("SET NAMES 'latin5'");
$isim = $_POST["isim"];
mysql_query("insert into deneme (isim) values ('".$isim."')");
?>
data is being inserted in database like this : ÄüÅıöç ÄÃÅİÃÃ
but I know if I do this in php :
$isim = iconv("utf-8","iso-8859-9",$_POST["isim"]);
data is being inserted without a problem : ğüşıöç ĞÜŞİÖÇ
so how can I do this in correct way ? I googled many many times, I cant figure out how can I do this. I know there is some iconv extensions for nodejs, but they are for linux not windows. Is there any method like iconv in javascript or nodejs (windows) ? or any extension for windows ? or any other suggestions ?
please dont say me change the php’s charset to utf-8, I can’t edit the php, I gave localhost as an example.
encodeURIComponentalways encodes as utf-8 (and then turns the resulting utf-8 bytes to percent-encoding), so I guess you have to use a library, or roll your own. I used some code from a library of mine to make this: