Url download produces chinese characters Topic is solved

Get help with using AutoHotkey (v1.1 and older) and its commands and hotkeys
braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Url download produces chinese characters

Post by braunbaer » 17 May 2022, 11:31

Hi, I use the following funtion with code that I found here in the forum, and that normally works:

Code: Select all

UrlDownload(Url) {
    whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
    whr.Open("GET", Url, true)
    whr.Send()
    ; Using 'true' above and the call below allows the script to remain responsive.
    whr.WaitForResponse()
    return whr.ResponseText
    }
When I try to download the page from https://myip.is I get a variable filled with a lot of chinese characters (or maybe japanese, or the like...)

Code: Select all

#+i::
MyIp(){
   page:=urldownload("https://myip.is/")
   msgbox %page%
   }

User avatar
mikeyww
Posts: 26869
Joined: 09 Sep 2014, 18:38

Re: Url download produces chinese characters

Post by mikeyww » 17 May 2022, 11:47

Just an alternative here.

Code: Select all

MsgBox, 64, IP address, % ip()

ip() { ; Get IP address
 Try whr := ComObjCreate("WinHttp.WinHttpRequest.5.1"), whr.Open("GET", "https://api.ipify.org/"), whr.Send()
 Catch
  Return
 Return whr.ResponseText
}

teadrinker
Posts: 4326
Joined: 29 Mar 2015, 09:41
Contact:

Re: Url download produces chinese characters  Topic is solved

Post by teadrinker » 17 May 2022, 13:15

Code: Select all

UrlDownload(Url) {
    whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
    whr.Open("GET", Url, true)
    whr.Send()
    ; Using 'true' above and the call below allows the script to remain responsive.
    whr.WaitForResponse()
    Arr := whr.responseBody
    pData := NumGet(ComObjValue(Arr) + 8 + A_PtrSize)
    length := Arr.MaxIndex() + 1
    Return StrGet(pData, length, "UTF-8")
    }

msgbox % page := urldownload("https://myip.is/")

MsgBox, % RegExReplace(page, ".+title=""copy ip address"">([^<]+).+", "$1")

braunbaer
Posts: 478
Joined: 22 Feb 2016, 10:49

Re: Url download produces chinese characters

Post by braunbaer » 17 May 2022, 16:54

Thank you both!

Both ways work fine.
As myip.is shows the IP address and in addition the host name, I will use teadrinkers function.

Post Reply

Return to “Ask for Help (v1)”