Created
September 19, 2022 06:30
-
-
Save 4t4nner/8a58689a21b628c4210286e8e11308da to your computer and use it in GitHub Desktop.
js: fetch with non-utf-8 response
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function transformWindows1251ToUTF8(response) { | |
const transformedBody = response.body | |
.pipeThrough(new TextDecoderStream("windows-1251")) | |
.pipeThrough(new TextEncoderStream("utf-8")); | |
return new Response(transformedBody); | |
} | |
fetch('https://vk.com/al_im.php', { | |
credentials: 'include', | |
method: 'POST', | |
headers: { | |
'content-type': 'application/x-www-form-urlencoded;charset=utf-8', | |
'x-requested-with': 'XMLHttpRequest', | |
'origin': 'https://vk.com' | |
}, | |
body: '_smt=im%3A2&act=a_dialogs_preload&al=1&gid=0&im_v=2&rs=' | |
}).then(transformWindows1251ToUTF8).then(resp=>resp.json()).then(console.log) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment