#DefineFunction UDF_www(objHTTP,oHTTP)
Ret=MapCreate()
knownHeaders=`User-Agent,Content-Type,Referer`
Err=ErrorMode(@OFF)
If MapKeyExist(oHTTP,`Proxy Enabled`) Then If MapKeyExist(oHTTP,`Proxy`) Then If oHTTP[`Proxy Enabled`] Then If oHTTP[`Proxy`]!=`` Then objHTTP.SetProxy(2,oHTTP[`Proxy`],``)
If MapKeyExist(oHTTP,`EnableRedirects`) Then objHTTP.Option(6)=oHTTP[`EnableRedirects`]
If !MapKeyExist(oHTTP,`Async`) Then oHTTP[`Async`]=@FALSE
objHTTP.Open(oHTTP[`Method`],oHTTP[`URL`],oHTTP[`Async`])
If MapKeyExist(oHTTP,`Username`) Then If MapKeyExist(oHTTP,`Password`) Then If oHTTP[`Username`]!=`` Then objHTTP.SetCredentials(oHTTP[`Username`],oHTTP[`Password`],0)
For i=1 to ItemCount(knownHeaders,`,`)
header=ItemExtract(i,knownHeaders,`,`)
If MapKeyExist(oHTTP,header) Then objHTTP.SetRequestHeader(header,oHTTP[header])
Next i
If MapKeyExist(oHTTP,`Headers`)
For i=1 to ItemCount(oHTTP[`Headers`],@CR)
header=ItemExtract(i,oHTTP[`Headers`],@CR)
objHTTP.SetRequestHeader(ItemExtract(1,header,@TAB),ItemExtract(2,header,@TAB))
Next i
EndIf
If !MapKeyExist(oHTTP,`Data`) Then oHTTP[`Data`]=``
objHTTP.Send(oHTTP[`Data`])
If oHTTP[`Async`]
If !MapKeyExist(oHTTP,`Timeout`) Then oHTTP[`Timeout`]=-1
objHTTP.WaitForResponse(oHTTP[`Timeout`])
EndIf
If MapKeyExist(oHTTP,`Filename`)
objStream=CreateObject(`ADODB.Stream`)
objStream.Type=1
objStream.Open()
objStream.Write(objHTTP.ResponseBody)
objStream.SaveToFile(oHTTP[`Filename`],2)
objStream.Close()
Drop(objStream)
Ret[`ResponseText`]=oHTTP[`Filename`]
Else
Ret[`ResponseText`]=objHTTP.ResponseText
EndIf
Ret[`GetAllResponseHeaders`]=StrReplace(objHTTP.GetAllResponseHeaders,@CRLF,@CR)
Ret[`Status`]=objHTTP.Status
Ret[`StatusText`]=objHTTP.StatusText
ErrorMode(Err)
Return Ret
#EndFunction
zAppName=`Testing Discord`
BoxTitle(zAppName)
BoxText(``)
zNow=TimeYmdHms()
zINI=zAppName:`.ini`
zAppFolder=IniReadPvt(`Settings`,`App Folder`,DirScript(),DirScript():zINI)
If StrSub(zAppFolder,StrLen(zAppFolder),1)!=`\` Then zAppFolder:=`\`
zINI=zAppFolder:zINI
oHTTP=MapCreate()
objHTTP=CreateObject(`WinHttp.WinHttpRequest.5.1`)
oHTTP[`User-Agent`]=IniReadPvt(`Settings`,`User-Agent`,`Mozilla/5.0 (Windows NT 10.0; Win64; x64; rv:91.0) Gecko/20100101 Firefox/91.0`,zINI)
oHTTP[`Proxy`]=`127.0.0.1:8888`
oHTTP[`Proxy Enabled`]=@False
zAPIendpoint=`https://discord.com/api/v9`
zBotToken=`***YOU HAVE TO GENERATE YOUR OWN TOKEN***`
oHTTP[`Content-Type`]=`application/x-www-form-urlencoded`
oHTTP[`Headers`]=`Authorization`:@TAB:`Bot `:zBotToken
oHTTP[`URL`]=zAPIendpoint:`/users/@me`
oHTTP[`Method`]=`GET`
Ret=UDF_www(objHTTP,oHTTP)
Rc=FilePut(DirScript():`Discord2.txt`,Ret[`ResponseText`])
Exit
I am in need of some assistance with Maps. The map "Ret" in the UDF_www has an issue. There should be 4 key-values but for the life of me I cannot get this to work. If you set a break point you will also notice some weird stuff happening with the map also - the "ResponseText" key-value does not populate in the debugger until the "GetAllResponseHeaders" value is populated (which it never does - and if you create a dummy key-value beforehand it will be deleted), before the "Status" and the "StatusText" values are populated (correctly).
Any help would be appreciated.