Skip to content

Instantly share code, notes, and snippets.

@4t4nner
Created September 19, 2022 06:30
Show Gist options
  • Save 4t4nner/8a58689a21b628c4210286e8e11308da to your computer and use it in GitHub Desktop.
Save 4t4nner/8a58689a21b628c4210286e8e11308da to your computer and use it in GitHub Desktop.
js: fetch with non-utf-8 response
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