首页 > 其他分享 >0146-Go-HTTP 客户端

0146-Go-HTTP 客户端

时间:2023-01-30 19:25:19浏览次数:52  
标签:HTTP scanner err resp 0146 Go 客户端

环境

  • Time 2022-08-25
  • Go 1.19

前言

说明

参考:https://gobyexample.com/http-clients

目标

使用 Go 语言的 HTTP 客户端。

示例

package main

import (
    "bufio"
    "fmt"
    "net/http"
)

func main() {

    resp, err := http.Get("https://gobyexample.com")
    if err != nil {
        panic(err)
    }
    defer resp.Body.Close()

    fmt.Println("Response status:", resp.Status)

    scanner := bufio.NewScanner(resp.Body)
    for i := 0; scanner.Scan() && i < 5; i++ {
        fmt.Println(scanner.Text())
    }

    if err := scanner.Err(); err != nil {
        panic(err)
    }
}

总结

使用 Go 语言的 HTTP 客户端。

附录

标签:HTTP,scanner,err,resp,0146,Go,客户端
From: https://www.cnblogs.com/jiangbo4444/p/17077036.html

相关文章

  • 0147-Go-HTTP 服务端
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/http-servers目标使用Go语言HTTP服务端。示例packagemainimport("fmt""ne......
  • 0148-Go-上下文
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/context目标使用Go语言的上下文。示例packagemainimport("fmt""net/http""time"......
  • 0149-Go-生成进程
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/spawning-processes目标使用Go语言生成进程。示例packagemainimport("fmt""......
  • 0150-Go-执行进程
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/execing-processes目标使用Go语言执行进程。示例packagemainimport("os""os......
  • 0151-Go-信号
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/signals目标使用Go语言的信号。示例packagemainimport( "fmt" "os" "os/signal" "......
  • 0152-Go-退出
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/exit目标退出Go程序。示例packagemainimport("fmt""os")funcmain(){......
  • 0138-Go-文件目录
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/directories目标使用Go语言处理文件目录。示例packagemainimport("fmt""os"......
  • 0139-Go-临时文件
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/temporary-files-and-directories目标使用Go语言处理临时文件。示例packagemainimport......
  • 0140-Go-内嵌命令
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/embed-directive目标使用Go语言的内嵌命令。示例packagemainimport("embed")/......
  • 0141-Go-单元测试
    环境Time2022-08-25Go1.19前言说明参考:https://gobyexample.com/testing-and-benchmarking目标使用Go语言进行测试。示例packagemainimport("fmt"......