Home > Article > Backend Development > How to Use Proxies with UTLS and HTTP 1.1 Requests?
Use Proxies with UTLS and HTTP 1.1 Requests
Question:
How do you connect to a host using UTLS with a randomized TLS fingerprint while utilizing an HTTP or SOCKS5 proxy?
Answer:
To use proxies with UTLS and HTTP 1.1 requests, you can follow these steps:
1. Create a Proxy Dialer:
First, create a proxy dialer that will dial the proxy and return a net.Conn. Here's a simplified example:
import ( "net/url" "github.com/magisterquis/connectproxy" "golang.org/x/net/proxy" ) var proxyString = "http://127.0.0.1:8080" dialTLS := func(network, addr string, _ *tls.Config) (net.Conn, error) { proxyURI, _ := url.Parse(proxyString) var proxyDialer proxy.Dialer switch proxyURI.Scheme { case "socks5": proxyDialer, _ = proxy.SOCKS5("tcp", proxyString, nil, proxy.Direct) case "http": proxyDialer, _ = connectproxy.New(proxyURI, proxy.Direct) } return proxyDialer.Dial("tcp", addr) }
2. Dial the Proxy and Create a UTLS Client:
Once you have a proxy dialer, dial the proxy to create a net.Conn. Then, use that net.Conn when creating the UTLS Client, before handshaking. For example:
import ( "github.com/refraction-networking/utls" ) uconn := utls.UClient(conn, cfg, &utls.HelloRandomizedALPN)
3. Send HTTP Request over UTLS Connection:
Finally, you can use the UTLS connection to send an HTTP 1.1 request. Here's how you can do it:
req := &http.Request{ Method: "GET", URL: &url.URL{Host: "www.example.com", Path: "/"}, Header: make(http.Header), } req.Proto = "HTTP/1.1" req.ProtoMajor = 1 req.ProtoMinor = 1 if err := req.Write(uconn); err != nil { return nil, err }
Additional Tips:
The above is the detailed content of How to Use Proxies with UTLS and HTTP 1.1 Requests?. For more information, please follow other related articles on the PHP Chinese website!