我正在尝试使用POST
发出"WinHttp.WinHttpRequest.5.1"
请求。如果我发送#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)
答案 0 :(得分:1)
尝试:
body = "{ ""FIRST"": " & DYNAMIC & ", ""second"": ""somestring"", ""third"": 100}"
其中DYNAMIC = """something"""
。