参考这个问题VBA XMLHTTP clear authentication?我也试图在VBA中传递基本身份验证。它运作得很好。
我唯一担心的是登录弹出窗口,只要在请求中发送了错误的用户标识或密码就会出现。有没有办法禁用它并从VBA本身向用户发送消息框,告诉他有关身份验证失败的信息?
更新
VBA代码:
Dim objHTTP As New MSXML2.XMLHTTP60
With objHTTP
.Open "GET", UrlUserService, False
.setRequestHeader "Content-Type", "application/json"
.setRequestHeader "Accept", "application/json"
.setRequestHeader "Cache-Control", "no-cache"
.setRequestHeader "Authorization", "Basic " + Base64Encode(userName + ":" + userPwd)
.setRequestHeader "Pragma", "no-cache"
.setRequestHeader "If-Modified-Since", "Sat, 1 Jan 2000 00:00:00 GMT"
.send ""
response = .Status
End With
答案 0 :(得分:0)
使用Msxml2.XMLHTTP.6.0协议,并将凭据作为请求的一部分传递
。打开“ GET”,pUrl,false,“ pUsername”,“ pPassword”