VBA-WEB无法使用httpbasic身份验证器授权

时间:2019-07-05 03:56:08

标签: excel vba rest

我正在尝试使用VBA-Web通过Excel VBA提交REST API并遇到问题

https://github.com/VBA-tools/VBA-Web

我试图修改此示例以使用HttpBasicAuthenticator,但未成功,它显示HTTP错误401。当我使用Postman提交其余请求时,就可以了。

https://github.com/revisohq/api-samples/tree/master/rest/excel

如果我使用不需要身份验证的网址。它按预期工作

https://rest.reviso.com/customers?demo=true

Private Sub Worksheet_Activate()
    Dim Client As New WebClient
    Dim Request As New WebRequest
    Client.TimeoutMs = 30000 ' 30 seconds

    Client.BaseUrl = "https://postman-echo.com/basic-auth"
    'Client.BaseUrl = "https://rest.reviso.com/customers?demo=true"
    Request.Format = WebFormat.Json

    Dim Auth As New HttpBasicAuthenticator
    Auth.Setup _
    Username:="postman", _
    Password:="password"


    Dim Response As WebResponse
    Set Response = Client.Execute(Request)

    If Response.StatusCode <> Ok Then
        Sheets("Test").Range("A1") = Response.StatusDescription
        Exit Sub
    End If

    Dim Json As Object
    Set Json = WebHelpers.ParseJson(Response.Content)

    FillData Json

End Sub

0 个答案:

没有答案