下面是一个简单的例子,使用Go语言发起GET请求:

package main

import (
    "fmt"
    "io/ioutil"
    "net/http"
)

func main() {
    // 发起GET请求
    resp, err := http.Get("https://www.baidu.com")
    if err != nil {
        fmt.Println(err)
        return
    }
    defer resp.Body.Close()

    // 读取响应body
    body, err := ioutil.ReadAll(resp.Body)
    if err != nil {
        fmt.Println(err)
        return
    }

    // 打印响应body
    fmt.Println(string(body))
}

以上代码会向百度发起GET请求,并返回响应body的内容。你可以根据你的需求修改请求的URL和其他参数

Go语言写个get的http请求

原文地址: https://www.cveoy.top/t/topic/fuDM 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录