Please note before configuration: Go needs to be executed in non-mainland network environment for IPFoxy proxy to take effect
After purchasing a rotating proxy, go to the [Rotating Residential Proxy] page and complete the following operations:
1. Protocol type: http
2. Format: Username: Password@Host:Port
3. Generate Proxy
4. Copy the generated connection information
1. Copy the following code into the Go code, and paste the proxy connection information just copied from IPFoxy into the code. For example, the proxy connection information is: username:password@gate-us-ipfoxy.io:58688
package main
import (
"fmt"
"io/ioutil"
"log"
"net/http"
"os"
)
func main() {
os.Setenv("HTTP_PROXY", "http://username:password@gate-us-ipfoxy.io:58688")
resp, err := http.Get("https://lumtest.com/myip.json")
fmt.Println(resp)
if err != nil {
panic(err)
}
defer resp.Body.Close()
if resp.StatusCode == http.StatusOK {
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
log.Fatal(err)
}
bodyString := string(bodyBytes)
fmt.Println(bodyString)
}
}