http请求的VBA代理自动配置 [英] VBA Proxy auto-configuration for http requests

查看:126
本文介绍了http请求的VBA代理自动配置的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要在VBA中为Web api构建客户端,并且它需要在代理(具有身份验证)之后工作.我一直在研究WinHttp.WinHttpRequest和MSXML2.XMLHTTP/ServerXMLHTTP类.事实证明:

I need to build a client for a web api in VBA and it needs to work behind a proxy (with authentication). I've been looking at the WinHttp.WinHttpRequest and MSXML2.XMLHTTP/ServerXMLHTTP classes. It turns out that:

  • XMLHTTP自动检测通过 proxy.pac 文件提供的代理设置(良好)
  • WinHttpRequest没有(坏)
  • XMLHTTP automatically detects proxy settings provided through a proxy.pac file (good)
  • WinHttpRequest doesn't (bad)

但是,另一方面:

  • XMLHTTP自动跟随重定向,并且没有禁用此行为(不好)
  • WinHttpRequest不好(很好)

由于我希望能够吃点蛋糕,所以有没有办法为诸如WinHttpRequest之类的组件提供自动代理配置,而不会盲目地跟随重定向?

Since I'd like to be able to have my cake and eat it, is there a way to get automatic proxy configuration for a component such as WinHttpRequest that doesn't follow redirects blindly?

推荐答案

VBA-Web项目可能会帮助您解决糕点食用问题.

The VBA-Web project might help you with your pastry eating problem.

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

我想您希望做的事情是这样的:

I guess what you wish to do would go something like:

Dim client As New WebClient
With client
    .BaseUrl = "https://www.google.com"
    .ProxyUsername = <user>
    .ProxyPassword = <password>
    .EnableAutoProxy = True
End With

Dim request As New WebRequest
With request
    .Method = WebMethod.HttpGet
    .Format = WebFormat.PlainText
End With

Dim response As WebResponse
Set response = client.Execute(request)

这篇关于http请求的VBA代理自动配置的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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