2014-04-18 25 views
2

正嘗試使用autohotkey爲使用autohotkey的海報請求創建一個帶有autohotkey的GUI。使用Autohot鍵的海報插件

防爆:

{ 
"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中得到響應。有些人可以幫我解決這個問題...我試圖搜索網頁,但找不到與autohotkey的海報插件相關的任何內容。

請幫助我們。

以下是我用

#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

你在哪裏有問題?向我們展示您的代碼! – MCL

回答

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 
+0

Awsm!...非常感謝你forivin ...它像魅力一樣工作.. !!!非常感謝你:) :) – user1856470

+0

嗨Forivin ...上面的代碼工作像魅力...但是有可能給代碼之前的json主體的輸入 例如在上面的代碼中的值在json中的sellId是硬編碼的,有可能在代碼運行之前給出sellId的值......將這些值附加到json主體中? – user1856470

+0

嗨forivin ....非常感謝你的幫助...我設法做到這一點我自己...!它的工作... :) – user1856470