0

I cannot get the system's correct proxy settings on Windows 10. The system-wide proxy configuration is setup to use a pac file:

enter image description here

There is a simple NodeJS server running on port 3000. It serves the pac file with the correct content type set to application/x-ns-proxy-autoconfig as suggested in this topic and here:

const http = require('http');
const fs = require('fs');

const hostname = '127.0.0.1';
const port = 3000;

const server = http.createServer((req, res) => {
  res.statusCode = 200;
  res.setHeader('Content-Type', 'application/x-ns-proxy-autoconfig');
  fs.readFile('proxy.pac', (err, data) => {
    if (err) throw err;
    res.end(data);
  });
});

server.listen(port, hostname, () => {
  console.log(`Server running at http://${hostname}:${port}/`);
});

The pac file is as simple as possible and just returns the address of the local proxy server (WinGate) on port 8888:

function FindProxyForURL(url, host) {
    return "PROXY 127.0.0.1:8888";
}

This setup works fine when the system's proxy is set manually to 127.0.0.1:8888 but when using the pac script the proxy isn't detected correctly.

The following code is used to obtain the system's proxy:

var url = new Uri("https://google.com");
var proxySettings = WebRequest.GetSystemWebProxy();
var host = proxySettings.GetProxy(url).ToString();

Debug.Log($"ProxyHost: {host}");

Output (automatic proxy): ProxyHost: https://google.com
Output (manual proxy): ProxyHost: http://127.0.0.1:8888/

What's wrong here and how can I detect the correct proxy settings using a proxy auto-configuration script?

Tayfe
  • 37
  • 5

0 Answers0