当前位置 博文首页 > Golang发送http GET请求的示例代码

    Golang发送http GET请求的示例代码

    作者:陶士涵 时间:2021-02-01 06:05

    使用标准库http来实现

    package tools
    
    import (
     "io/ioutil"
     "net/http"
    )
    
    func Get(url string)string{
     res, err :=http.Get(url)
     if err != nil {
      return ""
     }
     robots, err := ioutil.ReadAll(res.Body)
     res.Body.Close()
     if err != nil {
      return ""
     }
     return string(robots)
    }
    js