Go language uses HTTP tunneling

Go is an open source programming language that makes it easy to construct simple, reliable, and efficient software.

Go was developed by Robert Griesemer, Rob Pike, and Ken Thompson at the end of 2007, and later joined Ian Lance Taylor, Russ Cox, etc., and finally opened source in November 2009, and released Go 1 stable in early 2012 Version. Go development is now completely open and has an active community.

Go Language Features

  • Simple, fast and safe
  • Parallel, fun, open source
  • Memory management, array safety, fast compilation

Go language usage

The Go language was designed as a systems programming language for giant central servers hosting web servers, storage clusters, or similar.

For the field of high-performance distributed systems, the Go language undoubtedly has higher development efficiency than most other languages. It provides massive parallel support, which is perfect for game server development.

Embed the code to use tunnel mode HTTP

package main import ( "net/url""net/http""bytes""fmt""io/ioutil" ) const ProxyServer = "http://ip.hahado.cn:39010"type ProxyAuth struct { License string SecretKey string } func (p ProxyAuth) ProxyClient() http.Client { proxyURL, _ := url.Parse("http://" + p.License + ":" + p.SecretKey + "@" + ProxyServer) return http.Client{Transport: &http.Transport{Proxy:http.ProxyURL(proxyURL)}} } func main() { targetURI := "http://ip.hahaod.cn/ip"//targetURI := "http://ip.hahaod.cn/switch-ip"//targetURI := "http://ip.hahaod.cn/current-ip"// Initialize the proxy http client client := ProxyAuth{License: "username", SecretKey: "password"}.ProxyClient() request, _ := http.NewRequest("GET", targetURI, bytes.NewBuffer([] byte(``))) // 切换IP (只支持 HTTP) request.Header.Set("Proxy-Switch-Ip", "yes") response, err := client.Do(request) iferr != nil { panic("failed to connect: " + err.Error()) } else { bodyByte, err := ioutil.ReadAll(response.Body) iferr != nil { fmt.Println("读取 Body 时出错", err) return } response.Body.Close() body := string(bodyByte) fmt.Println("Response Status:", response.Status) fmt.Println("Response Header:", response.Header) fmt.Println("Response Body:\n", body) } }

Guess you like

Origin blog.csdn.net/weixin_73725158/article/details/130562716