Vbscript 获取 WinINET 的代理配置 API

Vbscript Get proxy config for WinINET API

我正在尝试将 HTTP get 发送到内部网络服务器,这工作正常,除非由于重新路由原因,用户必须遍历代理才能访问网络服务器,然后我只得到一个 WinInet 12029 "ERROR_INTERNET_CANNOT_CONNECT The attempt to connect to the server failed." 的错误请你帮我拉入现有的 Internet 选项代理配置?我不想静态定义代理凭据(我也没有尝试过)。

我的代码:

Function HTTPGet1
Dim o, URL, stat

URL = myURL
On Error Resume Next 
Set o = CreateObject("Microsoft.XMLHTTP")
' If Err.Number <> 0 Then
  'msgbox err.Number & err.Description
   'msgbox "cake" 
   'Exit Function
' End if
o.WinHttpGetIEProxyConfigForCurrentUser
o.open "GET", URL, False
o.send
stat = o.Status 'CInt(o.Status)
if stat = "200" then 
  msgbox "Account created successfully."
elseif stat = "" then
  msgbox "Connection attempt failed due to: " & err.description & "."
  err.clear
else
  msgbox "HTTP error code " & stat & " received."
end if
end function

感谢您的宝贵时间!

pcap 发现服务器正在响应此 API 无法响应的 SSL 证书错误。我将其换成 MSXML2.ServerXMLHTTP.6.0,然后能够处理主机名不匹配的问题。

Function HTTPGet1
Dim o, address, caseNo, URL, stat

URL = myURL
On Error Resume Next 
Set o = CreateObject("MSXML2.ServerXMLHTTP.6.0")
 If Err.Number <> 0 Then
   msgbox err.Number & err.Description
   err.clear
   Exit Function
 End if
o.setOption 2, SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS
o.open "GET", URL, False
o.send
stat = o.Status

参数 'SXH_SERVER_CERT_IGNORE_ALL_SERVER_ERRORS' 只是 API 可用的选项之一,而这个不是最安全的。

使用最新版本的 ServerXMLHTTP 对象

Set xHttp= CreateObject("MSXML2.ServerXMLHTTP.6.0")
xHttp.Open "POST", SERVER_URL, data, False
xHttp.setProxy 2, "<Your proxy URL>:<PORT>", ""
xHttp.send 
response = xHttp.responseText

msgbox xHttp.status & "|" & xHttp.statustext
msgbox "Response for get call is :" & response