在 Json 内分配动态值
Assigning Dynamic value within Json
我正在尝试使用 "WinHttp.WinHttpRequest.5.1"
执行 POST
请求。如果我按照 #1 中所示发送 JSON,它就会工作。但是,我想分配值并使用变量 (#2) 进行调用。有没有办法不使用第三方库就可以做到这一点?
DYNAMIC="Some dynamic value will be here"
'#1 Following works
'body = "{ ""FIRST"": ""dynamic"", ""second"": ""somestring"", ""third"": 100}"
'#2 Folowing call fails.
body = "{ ""FIRST"": DYNAMIC, ""second"": ""somestring"", ""third"": 100}"
TargetURL = "http://localhost:53518/api/Misc/myMethod/"
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.SetAutoLogonPolicy 0
HTTPReq.Open "POST", TargetURL, False
HTTPReq.setRequestHeader "Content-Type", "application/json"
HTTPReq.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
HTTPReq.setRequestHeader "Connection", "keep-alive"
HTTPReq.setRequestHeader "CacheControl", "no-cache"
HTTPReq.setRequestHeader "AcceptLanguage", "en-US,en;q=0.9,ht;q=0.8"
HTTPReq.setRequestHeader "AcceptEncoding", "gzip,deflate,br"
HTTPReq.setRequestHeader "Accept", "*/*"
HTTPReq.setRequestHeader "AcceptCharset", "UTF-8"
HTTPReq.send (body)
尝试:
body = "{ ""FIRST"": " & DYNAMIC & ", ""second"": ""somestring"", ""third"": 100}"
其中 DYNAMIC = """something"""
.
我正在尝试使用 "WinHttp.WinHttpRequest.5.1"
执行 POST
请求。如果我按照 #1 中所示发送 JSON,它就会工作。但是,我想分配值并使用变量 (#2) 进行调用。有没有办法不使用第三方库就可以做到这一点?
DYNAMIC="Some dynamic value will be here"
'#1 Following works
'body = "{ ""FIRST"": ""dynamic"", ""second"": ""somestring"", ""third"": 100}"
'#2 Folowing call fails.
body = "{ ""FIRST"": DYNAMIC, ""second"": ""somestring"", ""third"": 100}"
TargetURL = "http://localhost:53518/api/Misc/myMethod/"
Set HTTPReq = CreateObject("WinHttp.WinHttpRequest.5.1")
HTTPReq.SetAutoLogonPolicy 0
HTTPReq.Open "POST", TargetURL, False
HTTPReq.setRequestHeader "Content-Type", "application/json"
HTTPReq.setRequestHeader "User-Agent", "Mozilla/5.0 (Windows NT 10.0; WOW64)AppleWebKit/537.36 (KHTML, like Gecko) Chrome/72.0.3626.121 Safari/537.36"
HTTPReq.setRequestHeader "Connection", "keep-alive"
HTTPReq.setRequestHeader "CacheControl", "no-cache"
HTTPReq.setRequestHeader "AcceptLanguage", "en-US,en;q=0.9,ht;q=0.8"
HTTPReq.setRequestHeader "AcceptEncoding", "gzip,deflate,br"
HTTPReq.setRequestHeader "Accept", "*/*"
HTTPReq.setRequestHeader "AcceptCharset", "UTF-8"
HTTPReq.send (body)
尝试:
body = "{ ""FIRST"": " & DYNAMIC & ", ""second"": ""somestring"", ""third"": 100}"
其中 DYNAMIC = """something"""
.