2015-10-20 57 views
2

我需要编写vbscript来发送HTTP请求到组织拥有的机器的远程服务器。最初,我尝试了MSXML2.ServerXMLHTTP,但看起来有一些代理阻塞请求使用脚本。使用IE代理设置使用vbscript发送HTTP请求

我可以使用Internet Explorer发送请求就好了,所以IE配置了代理设置。

我的脚本现在看起来是这样的:

Set xHttp = CreateObject("Microsoft.XMLHTTP") 
'Set http = CreateObject("MSXML2.XMLHTTP") 

xHttp.Open "POST", SERVER_URL, data, False 
xHttp.Send 

有没有办法从IE获得代理设置,并在VBScript中以某种方式使用它?我无法在网上找到关于特定问题的任何参考。

回答

2

有一种可能的解决方法,你可以尝试使用IE内在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