问题描述
我需要编写vbscript以将HTTP请求发送到组织拥有的计算机的远程服务器.最初,我尝试使用MSXML2.ServerXMLHTTP
,但看起来有一些使用该脚本发出的代理阻止请求.
I need to write vbscript to send HTTP request to remote server for a machine owned by an organization. Initially, I tried with MSXML2.ServerXMLHTTP
but looks like there is some proxy blocking requests made using the script.
我可以使用Internet Explorer发送请求,因此IE已配置了代理设置.
I can send requests using Internet Explorer just fine, so IE has proxy settings configured.
我的脚本现在看起来像这样:
My script looks like this now:
Set xHttp = CreateObject("Microsoft.XMLHTTP")
'Set http = CreateObject("MSXML2.XMLHTTP")
xHttp.Open "POST", SERVER_URL, data, False
xHttp.Send
有什么方法可以从IE获取代理设置并以某种方式在vbscript中使用它吗?我在互联网上找不到有关特定问题的任何参考.
Is there any way to get proxy settings from IE and use it in vbscript somehow? I can't find any reference on internet about particular issue.
推荐答案
有一个可能的解决方法,您可以尝试使用IE固有XHR:
There is a possible workaround, you can try to use IE intrinsic XHR:
With CreateObject("InternetExplorer.Application")
.Visible = True ' debug only
.Navigate "https://www.google.com/" ' navigate to the same domain where the target file located
Do While .ReadyState <> 4 Or .Busy
wscript.Sleep 10
Loop
arrLocationURL = Split(.LocationURL, "/")
strLocationURL = arrLocationURL(0) & "//" & arrLocationURL(2) & "/" ' .com might be changed to certain Country code top-level domain
With .document.parentWindow
.execScript "var xhr = new XMLHttpRequest", "javascript" ' create XHR instance
With .xhr
.Open "GET", strLocationURL & "images/branding/googlelogo/2x/googlelogo_color_272x92dp.png", False ' open get request
.Send
arrContent = .responseBody ' retrieve binary content
End With
End With
.Quit
End With
With CreateObject("Adodb.Stream")
.Type = 1
.Open
.Write arrContent ' put content to the stream
.SaveToFile CreateObject("WScript.Shell").SpecialFolders.Item(&H0) & "\googlelogo.png", 2 ' save .png file to desktop
.Close
End With
更新
有一些有用的文章:
我想可能还有另一种可能的方式来使用IE代理设置而不使用IE本身.需要进一步的洞察力
I guess there might be another possible way to use IE proxy settings without IE itself. Need further insight
这篇关于使用IE代理设置使用vbscript发送HTTP请求的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!