首页 > 其他分享 >golang隧道模式示例

golang隧道模式示例

时间:2022-10-24 13:36:23浏览次数:57  
标签:http cn err 示例 ip fmt golang 隧道 response

package main import ( "net/url" "net/http" "bytes" "fmt" "io/ioutil" ) const ProxyServer = "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" // 初始化 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) if err != nil { panic("failed to connect: " + err.Error()) } else { bodyByte, err := ioutil.ReadAll(response.Body) if err != 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) } }


标签:http,cn,err,示例,ip,fmt,golang,隧道,response
From: https://blog.51cto.com/u_15822686/5789489

相关文章

  • golang隧道模式代码示例
    packagemainimport("net/url""net/http""bytes""fmt""io/ioutil")constProxyServer="ip.hahado.cn:39010"typeProxyAuthstruct{LicensestringSecretKe......
  • Sequence Flow示例
    准备实践环境[root@master~]#knservicecreatesq-appender-01--imageikubernetes/appender--envMESSAGE="-HandledbySQ-01"Creatingservice'sq-appender-0......
  • golang 开发辅助(一)
    理解goenv中的重要变量首先我们要来看一下goenv(目前版本1.16xxx)点击查看代码GO111MODULE=""GOARCH="amd64"GOBIN=""GOCACHE="/Users/dashuai/Library/Caches/go-......
  • 【Golang】通过Go Ballast 控制内存来优化性能
    一、关于GoGC优化的手段设置GOGC /debug.SetGCPercent()这两种方式的原理和效果都是一样的,GOGC默认值是100,也就是下次GC触发的heap的大小是这次GC之后的......
  • golang中的nil接收器
    索引:https://waterflow.link/articles/1666534616841我们先看一个简单的例子,我们自定义一个错误,用来把多个错误放在一起输出:typeCustomErrorstruct{ errors[]string......
  • golang postman workspaces(api)
    获取所有workspacespackagemainimport("fmt""net/http""io/ioutil")funcmain(){url:="https://api.getpostman.com/workspaces"method:="GET"client:......
  • 使用GoLang新建一个Go web file 文件服务
    packagemainimport( "github.com/gin-gonic/gin" "github.com/satori/go.uuid" "io" "net/http" "os" "path")const( //最大上传100M SR_File_Max_Bytes......
  • Golang:3.8、Golang包 package
    3.8、Golang包packageGolang包的定义和导入通常,文件夹名称和包名称相同,并且,同一个文件夹下面只有一个包定义包service/user_service.gopackageservice导入包mai......
  • Golang:4.1、Golang 并发编程-协程
    4.1、Golang并发编程-协程共语言中的并发是函数相互独立运行的能力。goroutines是并发运行的函数创建协程gotask()示例1packagemainimport("fmt""t......
  • ssh隧道
    本地端口转发将本地主机的5010端口绑定到远程主机的22端口ssh-p22-qngfNTL5010:localhost:[email protected]安静模式,不要显示作何debug信息-n重定向......