PJCHENder 未整理筆記

[Golang] pkg - net/http

2020-06-05

[Golang] pkg - net/http

type Response

type Response @ golang

func Get

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
package main

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

func main() {

resp, err := http.Get("https://pjchender.github.io")
if err != nil {
fmt.Printf("Error: %v", err)
os.Exit(1)
}

// 下面四句可以簡寫成一句
// io.Copy(os.Stdout, resp.Body)
bs := make([]byte, 99999)
n, err := resp.Body.Read(bs)
fmt.Println(n)
fmt.Println(string(bs))
}

掃描二維條碼,分享此文章