postData = ‘{“uname”:“15078381887”,“village_num”:“0003006”,“page”:“1”}’; var options = { hostname: ‘10.20.100.55’, port: ‘’, path: ‘xxxxxxxxxxxxxxxxxxxxxxxxxx’, method: ‘POST’, encoding: null, headers: { ‘User-Agent’: ‘Mozilla/5.0 (Windows NT 6.1; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/43.0.2357.134 Safari/537.36’, ‘Accept’: ‘text/html,application/xhtml+xml,application/xml;q=0.9,image/webp,/;q=0.8’, ‘Content-Type’: ‘application/json; charset=utf-8’, ‘Accept-Encoding’: ‘gzip, deflate’, ‘Accept-Language’: ‘zh-CN,zh;q=0.8’, ‘Cache-Control’: ‘no-cache’, ‘Connection’: ‘keep-alive’, ‘Host’: ‘10.20.101.43’, ‘Origin’: ‘http://10.20.101.43’, ‘Content-Length’: Buffer.byteLength(postData,‘utf8’) } };
var req = http.request(options, function(res){ console.log(‘STATUS:’ + res.statusCode); console.log('HEADERS: ’ + JSON.stringify(res.headers)); res.setEncoding(‘utf8’); var responseString = []; res.on(‘data’,function(chunk){ responseString.push(chunk); });
res.on('end', function(){
var response_body = iconv.decode(Buffer.concat(responseString), 'utf8'); //gb2312 win1252
console.log(response_body);
});
res.on('error', function(e){
console.log('problem with request: '+e.message);
});
});
req.write(postData); req.end();
返回的json乱码 请大神赐教