首页 > 其他分享 >华科云商golang详细示例代码

华科云商golang详细示例代码

时间:2022-10-25 14:02:10浏览次数:43  
标签:华科云商 http cn 示例 ip fmt golang targetURI response

packagemain



  import(



  "net/url"



  "net/http"



  "bytes"



  "fmt"



  "io/ioutil"



  )



  constProxyServer="ip.hahado.cn:39010"



  typeProxyAuthstruct{



  Licensestring



  SecretKeystring



  }



  func(pProxyAuth)ProxyClient()http.Client{



  proxyURL,_:=url.Parse("http://"+p.License+":"+p.SecretKey+"@"+ProxyServer)



  returnhttp.Client{Transport:&http.Transport{Proxy:http.ProxyURL(proxyURL)}}



  }



  funcmain(){



  targetURI:="http://ip.hahaod.cn/ip"



  //targetURI:="http://ip.hahaod.cn/switch-ip"



  //targetURI:="http://ip.hahaod.cn/current-ip"



  //初始化proxyhttpclient



  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("failedtoconnect:"+err.Error())



  }else{



  bodyByte,err:=ioutil.ReadAll(response.Body)



  iferr!=nil{



  fmt.Println("读取Body时出错",err)



  return



  }



  response.Body.Close()



  body:=string(bodyByte)



  fmt.Println("ResponseStatus:",response.Status)



  fmt.Println("ResponseHeader:",response.Header)



  fmt.Println("ResponseBody:\n",body)



  }



  }

  

 

标签:华科云商,http,cn,示例,ip,fmt,golang,targetURI,response
From: https://www.cnblogs.com/huakexiaopeng/p/16824621.html

相关文章

  • 国网B接口资源上报(Push_Resourse)接口描述和消息示例
    上篇blog,梳理了国网B接口的REGISTER接口描述和消息示例,前端系统加电启动并初次注册成功后,向平台上报前端系统的设备资源信息(包括:视频服务器、DVR/DVS、摄像机、告警设备、环......
  • 【转】VUE 组件注册使用示例
    首先是main.jsimport{createApp}from'vue'importAppfrom'./App.vue'import'./index.css'importSwiperfrom'./components/01.globalReg/Swiper.vue'imp......
  • golang隧道模式示例
    packagemainimport("net/url""net/http""bytes""fmt""io/ioutil")constProxyServer="ip.hahado.cn:3......
  • 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......