hello from http
This commit is contained in:
parent
1c0a6d298f
commit
33bbe945d5
13
xx-http-client.go
Normal file
13
xx-http-client.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import ("net/http"; "io/ioutil"; "fmt")
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
resp, err := http.Get("http://127.0.0.1:5000/")
|
||||||
|
if err != nil {
|
||||||
|
panic(err)
|
||||||
|
}
|
||||||
|
defer resp.Body.Close()
|
||||||
|
body, err := ioutil.ReadAll(resp.Body)
|
||||||
|
fmt.Print(string(body))
|
||||||
|
}
|
13
xx-http-server.go
Normal file
13
xx-http-server.go
Normal file
@ -0,0 +1,13 @@
|
|||||||
|
package main
|
||||||
|
|
||||||
|
import ("net/http"; "io")
|
||||||
|
|
||||||
|
func hello(res http.ResponseWriter, req *http.Request) {
|
||||||
|
res.Header().Set("Content-Type", "text/plain")
|
||||||
|
io.WriteString(res, "Hello From HTTP\n")
|
||||||
|
}
|
||||||
|
|
||||||
|
func main() {
|
||||||
|
http.HandleFunc("/", hello)
|
||||||
|
http.ListenAndServe(":5000", nil)
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user