const axios = require('axios');
const Encoding = require('encoding-japanese');
function toSJIS(keyword) {
const unicodeArray = Array.from(keyword, char => char.charCodeAt(0));
const sjisArray = Encoding.convert(unicodeArray, { to: 'SJIS', from: 'UNICODE' });
return Encoding.urlEncode(sjisArray);
};
async function test() {
const keyword = 'あああ';
const sjisKeyword = toSJIS(keyword);
const data = `param1=${sjisKeyword}¶m2=2`;
const response = await axios.post('https://example.com/xxxxx', data, {
headers: {
'Content-Type': 'application/x-www-form-urlencoded; charset=shift_jis'
},
responseType: 'arraybuffer',
transformResponse: data => new TextDecoder('shift-jis').decode(data)
});
console.log(response);
}
test();
More than 1 year has passed since last update.
Register as a new user and use Qiita more conveniently
- You get articles that match your needs
- You can efficiently read back useful information
- You can use dark theme