这是一个测试 Node.js 应用程序:
body = {
"message": {
"body": "hello", //it works
// "body":"привет", //doesn't work
"type":"TextMessage"
}
};
body = JSON.stringify(body);
headers = {
'Authorization': 'Basic ' + B64TOKEN,
'Host': SUBDOMAIN + '.campfirenow.com',
'Content-Type': 'application/json; charset=UTF-8',
'Content-Length': body.length
}
opts = {
host: SUBDOMAIN + '.campfirenow.com',
port: 443,
method: 'POST',
path: '/room/' + TEST_ROOM + '/speak.json',
headers: headers
}
request = require('https').request(opts, function(response) {
var data;
data = '';
response.setEncoding('utf8');
response.on('data', function(chunk) {
return data += chunk;
});
return response.on('end', function() {
console.log("===== start responce");
console.log(data);
console.log("===== end responce");
});
});
request.end(body);
body
地图是我要发送的。而且您可以看到"hello"
它可以正常工作(即发布到Campfire聊天的消息)但是"привет"
作为正文-发生错误...在第二种情况下,我从Campfire收到了很长的html响应...我认为如果我可以发送body
unicode 序列字符串...像这样:"body":"\u043f\u0440\u0438\u0432\u0435\u0442"
但是如何?