mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-08-12 05:33:04 +08:00
Create 15.2.md
This commit is contained in:
14
eBook/15.2.md
Normal file
14
eBook/15.2.md
Normal file
@@ -0,0 +1,14 @@
|
||||
# 15.2 一个简单的网页服务器
|
||||
|
||||
Http是一个比tcp更高级的协议,它描述了客户端浏览器如何与网页服务器进行通信。Go有自己的`net/http`包,我们来看看它。我们从一些简单的示例开始,
|
||||
首先编写一个“Hello world!”:[查看示例15.6](examples/chapter_15/hello_world_webserver.go)
|
||||
|
||||
我们引入了`http`包并启动了网页服务器,和15.1的`net.Listen("tcp", "localhost:50000")`函数的tcp服务器是类似的,使用`http.ListenAndServe("localhost:8080", nil)`函数,如果成功会返回空,否则会返回一个错误(可以指定localhost为其他地址,8080是指定的端口号)
|
||||
|
||||
|
||||
|
||||
## 链接
|
||||
|
||||
- [目录](directory.md)
|
||||
- 上一章:[tcp服务器](15.1.md)
|
||||
- 下一节:[写一个简单的网页应用](15.3.md)
|
Reference in New Issue
Block a user