Get "https://...": Proxy Authentication Required
Go returns the CONNECT status text as an error when the gateway answers 407. Build the URL with url.UserPassword to rule out escaping problems, then check the token in the dashboard.
Go is popular for fast crawlers and monitoring services because goroutines make high concurrency cheap. The standard net/http package supports authenticated HTTP and SOCKS5 proxies directly through the Proxy field of http.Transport, so no extra module is required.
Below you will build a client with a proxy, add targeting safely with url.UserPassword, switch to SOCKS5, and learn how connection reuse affects rotating and sticky IPs.
Updated 23 November 2026
net/http supports HTTP on port 8000 and SOCKS5 on port 9000 with a username and password in the proxy URL. Your username and token appear on the Proxy setup page of your dashboard after your first order.
Follow the steps in order. Replace YOUR_TOKEN with the token from your dashboard and change the country, city or session in the username to suit the job.
Go 1.21 or later is assumed. The examples use only the standard library until the Colly step.
mkdir proxycheck && cd proxycheck
go mod init proxycheckParse the proxy URL, credentials included, and set it on the Transport with http.ProxyURL. Go sends the Proxy-Authorization header for both plain HTTP requests and HTTPS tunnels.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"time"
)
func main() {
proxyURL, err := url.Parse("http://user-country-nl:YOUR_TOKEN@gate.firstproxy.shop:8000")
if err != nil {
panic(err)
}
client := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}
resp, err := client.Get("https://ipinfo.io/json")
if err != nil {
panic(err)
}
defer resp.Body.Close()
body, _ := io.ReadAll(resp.Body)
fmt.Println(resp.StatusCode, string(body))
}Building the URL as a struct avoids escaping mistakes and keeps targeting readable. This version adds a city and a sticky session.
func proxyFor(country, city, session string, ttl int) *url.URL {
user := "user-country-" + country
if city != "" {
user += "-city-" + city
}
if session != "" {
user += fmt.Sprintf("-session-%s-ttl-%dm", session, ttl)
}
return &url.URL{
Scheme: "http",
Host: "gate.firstproxy.shop:8000",
User: url.UserPassword(user, "YOUR_TOKEN"),
}
}
transport := &http.Transport{Proxy: http.ProxyURL(proxyFor("nl", "rotterdam", "w1", 15))}net/http accepts a socks5 scheme in the proxy URL and sends the target hostname to the proxy, so DNS is resolved at the exit. Use port 9000.
proxyURL, _ := url.Parse("socks5://user-country-nl:YOUR_TOKEN@gate.firstproxy.shop:9000")
client := &http.Client{
Timeout: 30 * time.Second,
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
}A Transport keeps connections open and reuses them, and a reused tunnel keeps its exit IP. For a fresh IP on every request with a rotating username, set DisableKeepAlives: true. For sticky work, give each session its own Transport and client and keep keep-alive on for speed.
// rotating: new connection, new IP per request
rotating := &http.Client{Transport: &http.Transport{
Proxy: http.ProxyURL(proxyFor("nl", "", "", 0)),
DisableKeepAlives: true,
}}
// sticky: one client per worker, each with its own session
for w := 0; w < 4; w++ {
go func(w int) {
c := &http.Client{Transport: &http.Transport{
Proxy: http.ProxyURL(proxyFor("nl", "", fmt.Sprintf("w%d", w), 20)),
}}
_ = c // use c for every request of this worker
}(w)
}
_ = rotatingColly v2 takes the proxy as a string with SetProxy, or a function with SetProxyFunc for per-request choices.
// go get github.com/gocolly/colly/v2
c := colly.NewCollector()
if err := c.SetProxy("http://user-country-nl:YOUR_TOKEN@gate.firstproxy.shop:8000"); err != nil {
log.Fatal(err)
}
c.OnResponse(func(r *colly.Response) { fmt.Println(string(r.Body)) })
c.Visit("https://ipinfo.io/json")Run the program from step 2. It prints the status code and the ipinfo.io JSON for the exit IP.
A working proxy returns a response like the one shown, trimmed to the main fields. The IP belongs to the exit, the city and country follow your username, and the time zone is where that IP is located, here Netherlands.
go run .{
"ip": "203.0.113.24",
"city": "Amsterdam",
"country": "NL",
"timezone": "Europe/Amsterdam"
}203.0.113.24 is a documentation address. Your result shows a real exit IP.
All targeting is written into the username, so Go needs no extra settings to change location. Parts are joined with hyphens in this order after your proxy user. The password is always your token.
| Part | Format | Example | Rule |
|---|---|---|---|
| Country | -country-{cc} | -country-nl | Required. Two-letter country code in lowercase. 64 countries are available. |
| City | -city-{city} | -city-amsterdam | Optional. City name in lowercase, spaces become hyphens. 172 cities are available. |
| Session | -session-{id} | -session-a1b2c3 | Optional. Any letters and digits you choose. The same id keeps the same IP, a new id gets a new IP. |
| Session length | -ttl-{minutes}m | -ttl-30m | Used with a session. Residential 1 to 120 minutes, mobile 1 to 60, long-acting ISP up to 720 (12 hours). |
user-country-nl-city-amsterdam-session-a1b2c3-ttl-30mFind country codes and city values on the proxy locations page.
The problems people run into most often with Go, with the message you are likely to see and how to solve it.
Go returns the CONNECT status text as an error when the gateway answers 407. Build the URL with url.UserPassword to rule out escaping problems, then check the token in the dashboard.
The client timeout fired. Keep Timeout on the client, add TLSHandshakeTimeout and ResponseHeaderTimeout on the Transport, and retry with a new session name.
The gateway host is misspelled or DNS on the machine is failing. Check the host in the proxy URL and test with curl from the same machine.
Connection reuse keeps the same tunnel. Set DisableKeepAlives: true on that Transport, or close idle connections with CloseIdleConnections() between batches.
Always close resp.Body, reuse clients instead of creating one per request, and cap MaxConnsPerHost so goroutines do not open unlimited tunnels.
All products share one account, one prepaid balance and the same gateway, so you can switch type by changing the product, not the code.
From $0.23 per GB
Rotating per connection for crawls, sticky per worker for session flows.
View residential proxiesFrom $0.58 per 100 IPs per month
Very low cost per IP for high-concurrency Go crawlers on lightly protected sites.
View shared datacenter proxiesFrom $11.90 per day
Flat daily price when goroutines push large daily traffic through home IPs.
View unlimited residential proxiesBuilding a scraper? The web scraping use case covers request rates, retries and product choice in more depth.
Short answers to what people ask most about using a proxy with Go.
Parse http://username:YOUR_TOKEN@gate.firstproxy.shop:8000 with url.Parse and set Transport: &http.Transport{Proxy: http.ProxyURL(u)} on the client. Go adds the proxy authentication header automatically.
Yes. net/http accepts socks5:// URLs in Transport.Proxy, including a username and password. golang.org/x/net/proxy is only needed for custom dialers.
The Transport reuses keep-alive connections, and each tunnel stays on its exit IP. Disable keep-alives for per-request rotation, or use a session name when you want the same IP on purpose.
The default Transport uses http.ProxyFromEnvironment, which reads HTTP_PROXY, HTTPS_PROXY and NO_PROXY. A custom Transport only does so if you set Proxy: http.ProxyFromEnvironment.
Test any proxy from the terminal with -x and -U, including SOCKS5 with remote DNS.
Programming languagesNode.js proxy setupfetch with undici ProxyAgent, axios with https-proxy-agent, and SOCKS5 agents.
Programming languagesJava proxy setupHttpClient with ProxySelector and Authenticator, the tunneling property, and OkHttp.
Scraping and automation librariesScrapy proxy setupProxy every request with meta proxy or a downloader middleware, plus sticky sessions.
Get your token and run the first Go request
Create an account, top up from $40 with crypto, and copy the gateway, username and token from the dashboard.