基于GO语言最简单的HTTP服务器
浏览器访问
http://127.0.0.1:9090/%E4%B8%BA%E4%BD%A0%E6%9C%8D%E5%8A%A1
服务端文件编码UTF-8
package main
import (
"fmt"
"net/http"
"log"
)
func Sp(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Fprintf(w, "hello,你好")
}
func main() {
http.HandleFunc("/为你服务", Sp)
fmt.Println("listen on port 9090")
err := http.ListenAndServe(":9090", nil);
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
浏览器访问
http://127.0.0.1:9090/%E4%B8%BA%E4%BD%A0%E6%9C%8D%E5%8A%A1
服务端文件编码UTF-8
package main
import (
"fmt"
"net/http"
"log"
)
func Sp(w http.ResponseWriter, r *http.Request) {
r.ParseForm()
fmt.Fprintf(w, "hello,你好")
}
func main() {
http.HandleFunc("/为你服务", Sp)
fmt.Println("listen on port 9090")
err := http.ListenAndServe(":9090", nil);
if err != nil {
log.Fatal("ListenAndServe:", err)
}
}
有疑问加站长微信联系(非本文作者)