-
Notifications
You must be signed in to change notification settings - Fork 72
/
Copy pathXMLHTTP_Post.ahk
71 lines (66 loc) · 1.91 KB
/
XMLHTTP_Post.ahk
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
;by LogicDaemon <www.logicdaemon.ru>
;This work is licensed under a Creative Commons Attribution-ShareAlike 4.0 International License <http://creativecommons.org/licenses/by-sa/4.0/deed.ru>.
XMLHTTP_PostForm(ByRef URL, ByRef POSTDATA, ByRef response:=0, ByRef moreHeaders:=0) {
;wrapper for older scripts
return XMLHTTP_Post(URL, POSTDATA, response, moreHeaders)
}
XMLHTTP_Post(ByRef URL, ByRef POSTDATA, ByRef response:=0, ByRef reqmoreHeaders:=0) {
If (IsObject(reqmoreHeaders)) {
If (reqmoreHeaders.HasKey("Content-Type")) {
moreHeaders := reqmoreHeaders
} Else {
moreHeaders := reqmoreHeaders.Clone()
moreHeaders["Content-Type"] := "application/x-www-form-urlencoded"
}
} Else {
moreHeaders := {"Content-Type": "application/x-www-form-urlencoded"}
}
return XMLHTTP_Request("POST", URL, POSTDATA, response, moreHeaders)
}
#include %A_LineFile%\..\XMLHTTP_Request.ahk
If (A_ScriptFullPath == A_LineFile) { ; this is direct call, not inclusion
tries:=20
retryDelay:=1000
Loop %0%
{
arg:=%A_Index%
argFlag:=SubStr(arg,1,1)
If (argFlag=="/" || argFlag=="-") {
arg:=SubStr(arg,2)
foundPos := RegexMatch(arg, "([^=]+)=(.+)", argkv)
If (foundPos) {
If (argkv1 = "tries") {
tries := argkv2
} Else If (argkv1 = "retryDelay") {
retryDelay := argkv2
} Else {
XMLHTTP_EchoWrongArg(arg)
}
} Else {
If (arg="debug") {
debug := Object()
FileAppend Включен режим отладки`n, **
} Else {
XMLHTTP_EchoWrongArg(arg)
}
}
} Else If (!URL) {
URL:=arg
} Else If (!POSTDATA) {
POSTDATA:=arg
} Else {
XMLHTTP_EchoWrongArg(arg)
}
}
Loop %tries%
{
response := Object()
If (XMLHTTP_PostForm(URL,POSTDATA, response))
Exit 0
sleep %retryDelay%
}
ExitApp response.status
}
XMLHTTP_EchoWrongArg(arg) {
FileAppend Неправильный аргумент: %arg%`n, **
}