Encoding Issues / WinHttpRequest object

Get help with using AutoHotkey and its commands and hotkeys
hAirypAulsAck
Posts: 5
Joined: 19 Nov 2017, 01:19
GitHub: hAirypAulsAck

Encoding Issues / WinHttpRequest object

29 Jan 2018, 06:58

ello mates
anyone can point me in the right direction for some error debugging in a situation like this?

Code: Select all

SetWorkingDir %A_ScriptDir%
#SingleInstance, Force

WebRequest := ComObjCreate("WinHttp.Winhttprequest.5.1")
WebRequest.open("GET","http://localhost:8111/gamechat?lastId=0")

Gui, Add, Text,  w2000 h2000 vMyText
SetTimer, UpdateOSD, 200
Gosub, UpdateOSD
Gui, Show, w800 h600 NA
return

UpdateOSD:
Sleep, 2000
WebRequest.send()
;FileAppend, % WebRequest.responseText, gameChatLog.txt, UTF-8
resText = % WebRequest.responseText
GuiControl, , MyText, %resText%
Gui, +Resize
return
Grabs the text fine when I'm getting other data, because it's all in english, but now that I'm trying to fetch Russian, or Cyrillic (i believe) to be more specific, I'm running into encoding problems.. I switched and tried AHK encoding version, also tried looking at the same output in sublime which is what I always use to convert.. didn't change when i tried outputting to text file so I'm thinking it has to do with WinHttpRequest object, but the msdn page didn't seem to mention encoding


Image
teadrinker
Posts: 1459
Joined: 29 Mar 2015, 09:41
Contact:

Re: Encoding Issues / WinHttpRequest object

29 Jan 2018, 11:40

Hello! Try using Msxml2.XMLHTTP (or Msxml2.XMLHTTP.6.0) instead of WinHttp.Winhttprequest.5.1.
hAirypAulsAck
Posts: 5
Joined: 19 Nov 2017, 01:19
GitHub: hAirypAulsAck

Re: Encoding Issues / WinHttpRequest object

29 Jan 2018, 22:22

Hey, I'm new to comObject but I feel I understand the jist of it, but when trying your suggestion I am prompted with
---------------------------
testttt.ahk
---------------------------
Error: 0x800C0005 - The system cannot locate the resource specified.
Source: msxml6.dll
Description: The system cannot locate the resource specified.


HelpFile: (null)
HelpContext: 0

Specifically: Send

Line#
015: req := ComObjCreate("Msxml2.XMLHTTP.6.0")
016: req.open("GET", "http://localhost:8111/gamechat?lastId=0", False)
---> 017: req.Send()
018: MsgBox,req.responseText "
" req.getAllResponseHeaders()
019: Exit
020: Exit
020: Exit

Continue running the script?
---------------------------
Yes No
---------------------------
in both cases... i.e. msxml3.dll and msxml6.dll
both exist within %WINDIR%\System32\msxml*.dll
downloaded and installled Microsoft XML Parser (MSXML) 3.0 Service Pack 7 (SP7) with no luck, restarted no luck
un-registered and re-registered dll's to no luck
placed dll in %A_ScriptDir%, no lucj

where is AHK looking?

on one of the msdn pages I saw something similar to dllcall, the c# equilivant whatevre it was being used, but this page says no such thing
https://autohotkey.com/boards/viewtopic.php?t=9554
hAirypAulsAck
Posts: 5
Joined: 19 Nov 2017, 01:19
GitHub: hAirypAulsAck

Re: Encoding Issues / WinHttpRequest object

29 Jan 2018, 22:29

Here is the cURL / HTTPie response (think json) if anyone has other suggestions

Code: Select all

http GET http://localhost:8111/gamechat?lastId=0
HTTP/1.1 200 OK
Access-Control-Allow-Methods: GET, POST, OPTIONS
Access-Control-Allow-Origin: *
Content-Length: 209
Content-Type: application/json

[
    {
        "enemy": false,
        "id": 1,
        "mode": "Team",
        "msg": "wubba lubba dubb dubb w",
        "sender": "diVineProportion"
    },
    {
        "enemy": false,
        "id": 2,
        "mode": "Team",
        "msg": "Guide on me!",
        "sender": "diVineProportion"
    }
]
I know i can use ahk to just read this like if exec to cli and save to txt, parse etc, but im trying to make a release that doesn't require the client to attain any additional programs /software.. i.e. curl etc
User avatar
noname
Posts: 509
Joined: 19 Nov 2013, 09:15

Re: Encoding Issues / WinHttpRequest object

30 Jan 2018, 00:14

soundcloud.com/user-32706894
mustang
Posts: 10
Joined: 25 Apr 2017, 03:12

Re: Encoding Issues / WinHttpRequest object

30 Jan 2018, 03:53

i use this function

Code: Select all

#NoEnv
#SingleInstance force
FileEncoding, UTF-8

url := "https://autohotkey.com"
httpQuery(html_code_raw, url)
Msgbox % html_code_raw

httpQuery(byref Result, lpszUrl, POSTDATA="", HEADERS="")
{
   WebRequest := ComObjCreate("WinHttp.WinHttpRequest.5.1")
   WebRequest.SetTimeouts(3000,3000,3000,3000)
Try { 
   WebRequest.Open("GET", lpszUrl)
   WebRequest.setRequestHeader("Content-Type", "application/x-www-form-urlencoded")
   WebRequest.Send(POSTDATA)
   WebRequest.WaitForResponse()
   Result := WebRequest.ResponseText
   WebRequest := ""
} catch e {
	Result := ""
}
}

Return to “Ask For Help”

Who is online

Users browsing this forum: boiler, TAC109, vsub, WeThotUWasAToad and 105 guests