Using nodejs https.request, we're making a POST request with contents
request.write(JSON.stringify(data))
One of the characters in request body is '£'. When this is present, the server responds with
unexpected token at '... ��...'
Adding utf-8 to content type doesn't make any difference:
'Content-Type': 'application/json; charset=utf-8',
How to fix this? Or, how can one set encoding for https.request content, if it's not already UTF-8?
Related question: Module request how to properly retrieve accented characters? � � �
Maybe this could work:
// Setup the request. The options parameter is
// the object we defined above.
var req = http.request(options, function(res) {
// Set the correct encoding of the data
res.setEncoding('utf-8');
var responseString = '';
res.on('data', function(data) {
responseString += data;
});
res.on('end', function() {
var resultObject = JSON.parse(responseString);
});
});