1

I am developing an application that has to connect through a HTTP Proxy and then use that Connection to do a GET Request to a domain name. The Domain Name should be resolved manually e.g. giving it the IP it should dial. Exactly thats the issue im facing.

prox, err := connectproxy.NewWithConfig(urll, proxy.Direct, &connectproxy.Config{
        ServerName: requestHostname,
        InsecureSkipVerify: true,
        Header: hd,
    })

tcpConn, err := prox.Dial("tcp", "customhostname.net:443")

req, _ := http.NewRequest("POST", "https://customhostname.net/auth", bytes.NewBuffer([]byte(str)))
    req.Header.Set("Host", "customhostname.net:443")

With the above code the IP Address is being resolved automatically using DNS. How can i feed the client with my own IP?

Packages used: "golang.org/x/net/proxy" "github.com/magisterquis/connectproxy"

Thanks in advance.

  • 1
    If you do a proxy request then the proxy is responsible for resolving the domain name in the URL. This is nothing specific to Go. Often the system behind the proxy cannot even resolve the domain. Apart from that *"and then use that Connection to do a GET Request to a domain name."* - you are doing a POST in your code and not a GET. – Steffen Ullrich Mar 30 '20 at 05:48
  • 1
    But if you tell the proxy to connect to a specific IP address you have to give this IP address in the CONNECT command instead of the hostname, i.e. `prox.Dial("tcp", "IP:443")`. The HTTP request then must contain the hostname again, since this is what the server at the end expects. – Steffen Ullrich Mar 30 '20 at 05:52
  • were you able to solve it? – John Balvin Arias May 28 '22 at 07:50

0 Answers0