XMLHttpRequest() - How to convert/decode ResponseText with latin characters/uncommon encoding?

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
Rafaews
Posts: 25
Joined: 16 Mar 2018, 21:19

XMLHttpRequest() - How to convert/decode ResponseText with latin characters/uncommon encoding?

27 Jul 2021, 20:35

I'm using this code from @Joe Glines's website to connect to an open page on Internet Explorer in order to use its cookies and then get some data:

Code: Select all

	oWindow:=ComObject(9,ComObjQuery(WBGet(),"{332C4427-26CB-11D0-B483-00C04FD90119}","{332C4427-26CB-11D0-B483-00C04FD90119}"),1)
	xhr := oWindow.XMLHttpRequest()
	xhr.Open("GET",URL,1) 
	xhr.send()
	while(xhr.ReadyState!=4) ;Wait for it to complete
		Sleep,50
		
	MsgBox % XHR.ResponseText
But the latin characters are missing.

On the page source it says "charset=windows-1252"

IE defaults to Encoding: Western European (ISO) which works.

On MsgBox characters like í or ó are missing as well as a few characters after. On notepad++ they are missing but a single '?' is on place.

A_IsUnicode = "Unicode"

I tried lots of things, Headers, SafeArrayAccessData, Fileappending and then Filereading.. But with no success. I don't know much about char encoding.. Anyone knows how to process/convert/interpret a ResponseText with a different encoding?
:crazy:
Rafaews
Posts: 25
Joined: 16 Mar 2018, 21:19

Re: XMLHttpRequest() - How to convert/decode ResponseText with latin characters/uncommon encoding?

28 Jul 2021, 17:15

Solved using:

Code: Select all

out := ""
		responseBody := XHR.ResponseBody
		loop % responseBody.MaxIndex() + 1
			out .= Chr(responseBody[A_Index - 1])

Return to “Ask for Help (v1)”

Who is online

Users browsing this forum: DataLife, Google [Bot], pgeugene, Rohwedder and 128 guests