0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 1 year has passed since last update.

shift-jisのURLにaxiosでpostする

Last updated at Posted at 2023-10-08
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}&param2=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();
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?