我正在尝试使用autohotkey创建一个带有autohotkey的GUI,用于海报请求。
代表:
{
"hwId":"2703",
"clientApiVersion":"1.0.0",
"sellId":"123456",
"uid":"123456",
"targetUserId":"123456",
"templateId":"123456",
"overrideValues": [{"name":"USERNAME","value":"test"}],
"customMessages": [{"name":"key1","value":"value1"},{"name":"key2","value":"value2"}],
"language":"en",
"verificationCode":"code",
"badge":"33",
}
这是我使用的海报正文。这些是输入,输出显示。通常当我发送POST请求时,我会在json中收到回复。有些人可以帮我解决这个问题...我试过在网上搜索但是找不到任何与海报插件有关的东西。
请帮助我们。
以下是我使用的代码
#NoEnv
#SingleInstance, Force
;InputBox, pass, Password, Enter password.
URL := "https://examplesite.com/exchange/api/ios/sendPushNotificationTemplateByUid"
;PostData := "username=Pulover&password=" pass
PostData := "
(
hwId=2703,
clientApiVersion=1.0.0,
sellId=865895,
uid=573675618,
targetUserId=573675618,
templateId=78,
language=en,
verificationCode=code,
badge=50,
)"
oHTTP := ComObjCreate("WinHttp.WinHttpRequest.5.1")
;Post request
oHTTP.Open("POST", URL , False)
;Add User-Agent header
oHTTP.SetRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
;Add Referer header
oHTTP.SetRequestHeader("Referer", URL)
;Add Content-Type
oHTTP.SetRequestHeader("Content-Type", "application/JSON")
;Send POST request
oHTTP.Send(PostData)
;Get received data
Gui, Add, Edit, w800 r30, % oHTTP.ResponseText
Gui, Show
return
GuiClose:
ExitApp
答案 0 :(得分:1)
示例正文用JSON编写。因此,我强烈建议您使用JSON库。这是我迄今为止一直使用的那个没有任何问题:http://pastebin.com/6EzQAHbH
只需将其保存为脚本目录中的jsonParser.ahk即可。我给你写了一个很清楚的例子,我认为你在寻找:
#Include jsonParser.ahk
url := "https://examplesite.com/exchange/api/ios/sendPushNotificationTemplateByUid"
username := "USERNAME"
Gui, Add, Edit, w800 r30 vResponseEdit
Gui, Show
body_AhkObj := {"hwId": "2703"
,"clientApiVersion": "1.0.0"
,"sellId": "123456"
,"uid": "123456"
,"targetUserId": "123456"
,"templateId": "123456"
,"overrideValues": [{"name":username,"value":"test"}]
,"customMessages": [{"name":"key1","value":"value1"}, {"name":"key2","value":"value2"}]
,"language": "en"
,"verificationCode": "code"
,"badge": "33"}
;change the sellId after the object was created
body_AhkObj.sellId := "987654321"
;;;;;;;;
body_JsonCode := BuildJson(body_AhkObj)
WinHttpObj := ComObjCreate("WinHttp.WinHttpRequest.5.1")
WinHttpObj.Open("POST", url)
WinHttpObj.SetRequestHeader("User-Agent", "Mozilla/5.0 (compatible; MSIE 9.0; Windows NT 6.1; WOW64; Trident/5.0)")
WinHttpObj.SetRequestHeader("Referer", url)
WinHttpObj.SetRequestHeader("Content-Type", "application/JSON")
WinHttpObj.Send(body_JsonCode)
GuiControl,, ResponseEdit, % WinHttpObj.ResponseText
Return
GuiClose:
ExitApp
Return