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

华科golang详细示例代码

时间:2022-10-20 14:37:55浏览次数:45  
标签: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/16809743.html

相关文章

  • 华科简化版 API使用(HTTP篇)
    简化版API使用1、使用浏览器1.1、获取当前IP(限制1200次/小时)用浏览器访问http://ip.hahado.cn/simple/current-ip?username=username&password=passw......
  • .NET(C#) System.Linq中实现多列group by(分组)的示例代码
    本文主要介绍.NET(C#)中,使用Linq时实现对多列数据进行分组的方法及示例代码。 1、C#3或更高版本使用匿名类型//声明式查询语法varresult3=fromxintab......
  • Hudi 数据湖的插入,更新,查询,分析操作示例
    Hudi数据湖的插入,更新,查询,分析操作示例作者:Grey原文地址:博客园:Hudi数据湖的插入,更新,查询,分析操作示例CSDN:Hudi数据湖的插入,更新,查询,分析操作示例前置工作首先,需要......
  • golang os.Args (转)
    转自:301-golang之命令行参数os.Argsos.Args获取运行时的参数,是一个切片Slice,第一个值是当前可运行文件的绝对路径import("os""fmt")funcmain(){......
  • 爱上开源之golang入门至实战第四章函数(Func)(八)
    爱上开源之golang入门至实战第四章函数(Func)(八)4.4.8函数作为返回值在go语言里,func本质上是一个类型关键字。使用func来进行声明,本质上就是什么了一个func的对象。对象......
  • 我的Vue之旅 07 Axios + Golang + Sqlite3 实现简单评论机制
    第三期·使用Vue3.1+TailWind.CSS+Axios+Golang+Sqlite3实现简单评论机制效果图CommentArea.vue我们需要借助js的Data对象把毫秒时间戳转化成UTCStrin......
  • 我的Vue之旅 07 Axios + Golang + Sqlite3 实现简单评论机制
    第三期·使用Vue3.1+Axios+Golang+Sqlite3实现简单评论机制效果图CommentArea.vue我们需要借助js的Data对象把毫秒时间戳转化成UTCString()。并在模板......
  • Golang编辑器 - GoLand安装
    GoLand官网https://www.jetbrains.com.cn/go/下载GoLand通过访问其官网进行安装包下载下载完成之后双击运行安装程序点击Next选择安装的路径下一步选择创建......
  • golang中的init初始化函数
    0.1、索引https://waterflow.link/articles/16660905308801、概念1.1、源文件里的代码执行顺序init函数是用于初始化应用程序状态的函数。它不接受任何参数并且不返回......
  • golang中的init初始化函数
    0.1、索引https://waterflow.link/articles/16660905308801、概念1.1、源文件里的代码执行顺序init函数是用于初始化应用程序状态的函数。它不接受任何参数并且不返......