excel - VBA-WEB 无法使用 httpbasic 身份验证器进行授权
问题描述
我正在尝试使用 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
如果我使用这个不需要身份验证的 URL。它按预期工作
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
解决方案
推荐阅读
- swiftui - 如何从使用 NavigationLink 创建的视图中初始化 ObservedObject?
- android - Android 中 FilePath 的 ImageView 加载问题(截断)
- ruby - 如何在 ubuntu 框中使用 nohup 命令让我的 ruby 服务器在后台运行
- sql-server - 更新语句 SQL 中的变量
- rust - 如果我已经有像 epoll / kqueue / IOCP 这样的非阻塞 IO,为什么还需要 async / await?
- html - 如何动态插入带有角度绑定的html
- amazon-web-services - CodeBuild 找不到目标 Internet 网关的 0.0.0.0/0 目的地
- java - 在spring boot java中从数据库生成xml
- python - Matplotlib .plot() 不打印所有数据点
- angular - 角度上的无线电输入值是字符串,我可以得到数字吗?