workspace/go/web/clientでclient.goファイルを作成する。
package main
import (
	"fmt"
	"log"
	"net/http"
	"net/http/httputil"
)
func main() {
	resp, err := http.Get("http://localhost:8889")
	defer resp.Body.Close()
	if err != nil {
		log.Fatal(err)
	}
	dump, err := httputil.DumpResponse(resp, true)
	if err != nil {
		log.Fatal(err)
	}
	fmt.Println(string(dump))
}
resp, err := http.Get("http://localhost:8889")でサーバにアクセスする。dump, err := httputil.DumpResponse(resp, true)でサーバからクライアントに返ってきたレスポンスをdumpという変数で人が理解できる形でとってくる。
MING64のコマンドラインに下記のコードを入力する。
$ cd ~/workspace/go/server/
$ go run server.go
別の端末(MINGW64)を開き、下記のコードを入力する。
$ cd ~/workspace/go/client/
$ go run client.go
そうると、下記の画面がコマンドラインに表示される。これがクライアントが受け取るレスポンスである。
HTTP/1.1 200 OK
Content-Length: 68
Content-Type: text/html; charset=utf-8
Date: Thu, 14 Jun 2018 06:25:35 GMT
<html><head><title>app</title></head><body>hello world</body></html>
HTTP/1.1 200 OKは、httpのプロトコルが通信できたことを意味する。Content-Length: 68は、bodyの長さで、Content-Type: text/html; charset=utf-8は、charset=utf-8という言語でtextがhtmlで書かれていること意味する。
Date: Thu, 14 Jun 2018 06:25:35 GMTで、標準時間を表し、<html><head><title>app</title></head><body>hello world</body></html>がサーバーに書かれている内容である。




