如何使用VBA脚本调用REST api

问题描述 投票:0回答:1
Dim WHTTP As Object
Set WHTTP = CreateObject("WinHttp.WinHttpRequest.5.1")    

mainUrl = "https://googlesample.api.google/okta"
myuser = "myluckyuser"
mypass = "myluckypassword"

strAutheticate = "username=" & myuser & "& password=" & mypass
WHTTP.Open "POST", mainUrl, False
'WHTTP.setRequestHeader "apikey", "[Token]"
WHTTP.setRequestHeader "Content-Type", "application/json"
WHTTP.send strAutheticate

Dim response As String

??? How to I receive the token here ????

我正在尝试使用 REST 调用 API 并获取令牌。

所以应该返回“access_token”:“blah134hao9u098-098-09”;

vba http-post
1个回答
0
投票
Dim tokenHTTP As Object
Set tokenHTTP = CreateObject("MSXML2.ServerXMLHTTP")
Dim tokenJSON As String
Dim tokenURL As String
Dim accessToken As String
tokenURL = "https://googlesample.api.google/okta"
tokenHTTP.Open "POST", tokenURL, True
tokenHTTP.setRequestHeader "Content-type", "application/json"
tokenHTTP.setRequestHeader "username", "myusername"
tokenHTTP.setRequestHeader "password", "mypassword"

tokenHTTP.send (tokenURL)
tokenJSON = tokenHTTP.responseText 
© www.soinside.com 2019 - 2024. All rights reserved.