Your Crawlhub connection
| Field | Value |
|---|---|
| Gateway | Use the assigned host and port for your client’s protocol. |
| Residential username | Copy the username from your configured residential connection. |
| ISP / Datacenter username | Use the username and port assigned to your product. |
Scroll horizontally to read all columns.
Use the protocol supported by this client. The examples below use PROXY_SERVER or separate host/port fields for these connection values. Read the proxy parameter reference.
Prepare the client
You need a current Go release. The example uses only the standard library.
Save it as main.go and start it with go run main.go.
url.UserPassword puts the username and password into the proxy URL and escapes special characters for you. Do not build the URL by joining strings.
Put your proxy login in environment variables, not in the code. Copy the username and password from your dashboard.
export PROXY_USERNAME="your-proxy-username"
export PROXY_PASSWORD="your-proxy-password"Connection example
The example connects to http://proxy.crawlhub.ai:8000 and prints the exit IP that the target sees.
package main
import (
"fmt"
"io"
"net/http"
"net/url"
"os"
"time"
)
func main() {
proxyURL := &url.URL{
Scheme: "http",
User: url.UserPassword(os.Getenv("PROXY_USERNAME"), os.Getenv("PROXY_PASSWORD")),
Host: "proxy.crawlhub.ai:8000",
}
client := &http.Client{
Transport: &http.Transport{Proxy: http.ProxyURL(proxyURL)},
Timeout: 30 * time.Second,
}
resp, err := client.Get("https://api.ipify.org")
if err != nil {
fmt.Fprintln(os.Stderr, "request failed:", err)
os.Exit(1)
}
defer resp.Body.Close()
ip, err := io.ReadAll(resp.Body)
if err != nil {
fmt.Fprintln(os.Stderr, "read failed:", err)
os.Exit(1)
}
fmt.Println("Exit IP:", string(ip))
}Add a country or session
Add options to the end of the username. The password stays the same. __cc_us picks a US exit. __cc_us__sid_job01 picks a US exit and keeps the same IP while you reuse that session ID.
// US exit
user := os.Getenv("PROXY_USERNAME") + "__cc_us"
// Or a US exit that keeps the same IP for session job01
// user := os.Getenv("PROXY_USERNAME") + "__cc_us__sid_job01"
proxyURL := &url.URL{
Scheme: "http",
User: url.UserPassword(user, os.Getenv("PROXY_PASSWORD")),
Host: "proxy.crawlhub.ai:8000",
}Put the country before the session. Read the proxy parameter reference for all options.
Reuse the client
Create one http.Client and Transport for each proxy setting and reuse them. The Transport keeps a pool of open connections.
Close every response body, as the example does, so connections go back to the pool.
Verify the connection
Run the example. It prints the exit IP, which is the address of the proxy, not your own. Run it again without a session ID and the IP can change.
Use a public HTTPS target on port 443. The gateway also forwards plain http:// on port 80. It refuses other ports and private or local addresses. Keep TLS verification on.
When it fails
407 means the proxy did not accept the login. Check the username, the password and the options you added. client.Get returns an error that names Proxy Authentication Required. A 407 can also mean that the trial ended or no traffic is left, so check your dashboard.
403 means the gateway refused the target, for example a port other than 80 or 443. 502 means the exit or the target did not answer. Retry after a short wait.
See Troubleshooting for other errors. Send your client version and the error text, without your password, to support.