我想经常向同一个网站 API 发出请求,该 API 以 .json 地理定位数据字符串响应,原则上它工作正常。但只有前一到两次调用,此后 JSON_Response_String
保持不变,即使我的实际地理位置数据同时发生变化(并且相同的网站 API 也会在网络浏览器中刷新其地址时反映这种变化,尽管有时它有点滞后).
出于相同目的,相同的代码可以很好地处理 CMD-CURL 请求(但这是不切实际的,因为据我所知,CMD 不能直接输出到 AHK 变量),所以问题一定是用 Microsoft 的 win32- object "WinHttp.WinHttpRequest.5.1" 或者我假设 AHK 处理它的方式。也许这也只是我:-)
你能发现错误吗?
;/* ---------------------------------------------------------------- */
;/* Function Definition */
;/* ---------------------------------------------------------------- */
Get_Show_Once(){
My_Country := ""
;/* -------------------- WebRequest (AHK-style) -------------------- */
whr := ComObjCreate("WinHttp.WinHttpRequest.5.1")
whr.Open("GET", "http://ip-api.com/json", true)
whr.Send()
whr.WaitForResponse()
JSON_Response_String := whr.ResponseText
MsgBox % JSON_Response_String
;/* --------------------------- Country --------------------------- */
MyRegexForCountry = (?<=country":")[\w\s]+
RegExMatch(JSON_Response_String, MyRegexForCountry , OutputVar)
My_Country := OutputVar
;/* -------------- Create & roughly position ToolTip --------------- */
CoordMode, ToolTip, Screen
ToolTip, %My_Country%, 0, 1337, 20
;/* --------- Fine-tune position dynamically (in hindsight) -------- */
WinGet, hWnd, ID, ahk_class tooltips_class32
WinGetPos, , , vPosW, vPosH, ahk_id %hWnd%
WinMove, ahk_id %hWnd%, , % 0, % (A_ScreenHeight-vPosH)
;/* ------------- Update w/o pausing other AHK-scripts ------------- */
SetTimer, UpdateWithoutSleeping, 5000 ; every 5 seconds
return
}
;/* --------------------------------------------------------------- */
;/* Recursive Function call(s) */
;/* ---------------------------------------------------------------- */
Get_Show_Once()
UpdateWithoutSleeping:
Get_Show_Once()
return