Skip to content

Instantly share code, notes, and snippets.

@Knovour
Last active August 29, 2015 13:56
Show Gist options
  • Save Knovour/8911841 to your computer and use it in GitHub Desktop.
Save Knovour/8911841 to your computer and use it in GitHub Desktop.
var iconv = require('iconv-lite');
var buf = iconv.encode('測試', 'big5'); // <buffer B4 FA B8 D5>
var bufLength = buf.length;
var test = '';
for (var i = 0; i < bufLength; i++)
test += '%' + buf[i].toString('16').toUpperCase();
// test = %B4%FA%B8%D5
var smsData = {
username: 'username',
password: 'password',
smbody: encodeToBig5('測試'),
dstaddr: 'dstaddr'
};
// Create query
var query = unescape(querystring.stringify(smsData));
// auerystring.stringify => 'username=username&password=password&smbody=%25B4%25FA%25B8%25D5&dstaddr=dstaddr'
// auerystring.stringify will encode '%' to '%25'
// use unescape to turn '%25' back
// unescape => 'username=username&password=password&smbody=%B4%FA%B8%D5&dstaddr=dstaddr'
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment