Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save justaguywhocodes/7704771d3e9818b93651ba8d07189f6c to your computer and use it in GitHub Desktop.
Save justaguywhocodes/7704771d3e9818b93651ba8d07189f6c to your computer and use it in GitHub Desktop.
<html>
<head>
<title>Proxy Download Example</title>
<HTA:APPLICATION ID="ProxyDownload" APPLICATIONNAME="Proxy Download" BORDER="thin" BORDERSTYLE="normal" SINGLEINSTANCE="yes" WINDOWSTATE="normal" />
<script language="JScript">
function downloadFile() {
try {
// Create WinHTTP request object
var winHttp = new ActiveXObject("WinHttp.WinHttpRequest.5.1");
// Set proxy: 2 = HTTPREQUEST_PROXYSETTING_PROXY, proxy server, bypass list (e.g., "<local>" for local addresses)
winHttp.SetProxy(2, "http://yourproxy:port", "<local>");
// Set proxy credentials if authentication is required (flag 1 = HTTPREQUEST_SETCREDENTIALS_FOR_PROXY)
// Use basic auth; for NTLM or other schemes, WinHTTP may negotiate automatically
winHttp.SetCredentials("username", "password", 1);
// Enable HTTPS support (ignore server certificate errors if needed, but not recommended for production)
// winHttp.Option(9) = 0x3300; // WinHttpRequestSecureProtocols (SSL2/3 + TLS1/1.1/1.2)
// Open GET request to the URL (example: README from a GitHub repo)
var url = "https://raw.githubusercontent.com/octocat/Hello-World/master/README";
winHttp.Open("GET", url, false); // false = synchronous
// Send the request
winHttp.Send();
// Check response status
if (winHttp.Status === 200) {
// Create stream to save binary data
var stream = new ActiveXObject("ADODB.Stream");
stream.Type = 1; // adTypeBinary
stream.Open();
stream.Write(winHttp.ResponseBody);
stream.SaveToFile("C:\\Downloads\\readme.txt", 2); // 2 = adSaveCreateOverWrite; adjust path as needed
stream.Close();
alert("File downloaded successfully to C:\\Downloads\\readme.txt");
} else {
alert("Download failed. Status: " + winHttp.Status + " - " + winHttp.StatusText);
}
} catch (e) {
alert("Error: " + e.message);
}
}
</script>
</head>
<body>
<button onclick="downloadFile()">Download File via Proxy</button>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment