Use IE proxy settings to send HTTP request using vbscript

让人想犯罪 __ 提交于 2019-12-06 10:51:28

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

UPDATE

There are some useful articles:

Using Fiddler with WinHTTP

WinINet vs. WinHTTP

I guess there might be another possible way to use IE proxy settings without IE itself. Need further insight

Use the latest version of ServerXMLHTTP object

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

I hope this is the exact answer to your question. Instead of using the complicated approach of InternetExplorer.Applciation

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!