VBA中的默认凭据 [英] default credentials in VBA

查看:73
本文介绍了VBA中的默认凭据的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试从VB for Applications(VBA)发出HTTP请求 那应该很简单:

I'm tryng to make a HTTP request from VB for Applications ( VBA) that should have been simple:

URL = "https://www.google.com/"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "GET", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.Send
MsgBox xhr.responseText

但是我在需要基本身份验证(base64)的代理服务器后面.

BUT I'm behind a proxy server which require basic auth (base64).

如何在VBA中设置凭据?

How to set the credentials in VBA ?

(相当于:myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials)

(something equivalent to : myHttpWebRequest.Credentials = CredentialCache.DefaultCredentials)

如果这不可能,如何用另一种方法解决问题?

If this is not possible, how to solve the issue with another approach ?

谢谢!

推荐答案

您将需要setProxyCredentials方法.我没有要测试的代理,但这应该可以解决问题:

You'd need the setProxyCredentials method. I don't have a proxy to test, but this should do the trick:

URL = "https://www.google.com/"
Set xhr = CreateObject("MSXML2.ServerXMLHTTP.6.0")
xhr.Open "GET", URL, False
xhr.setRequestHeader "Content-Type", "application/x-www-form-urlencoded"
xhr.setProxy 2, "192.168.0.222:8080"
xhr.setProxyCredentials "your_username" , "password_for_username"
xhr.Send
MsgBox xhr.responseText

来自此问题指出2参数是您可能需要更改的版本号.

Taken from This Question which points out the 2 argument is a version number that you may need to change.

这篇关于VBA中的默认凭据的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆