Update 15.3.md

This commit is contained in:
glight2000
2015-12-12 20:38:48 +08:00
parent 15548462b3
commit 00bde4ba15

View File

@@ -120,6 +120,28 @@ status: Robot cars invade California, on orders from Google: Google has been tes
* `http.NotFound(w ResponseWriter, r *Request)`这个函数将返回网页没有找到HTTP 404错误。
* `http.Error(w ResponseWriter, error string, code int)`这个函数返回特定的错误信息和HTTP代码。
*`http.Request`对象的一个重要属性`req``req.Method`,这是一个包含`GET``POST`字符串,用来描述网页是以何种方式被请求的。
```
go为所有的HTTP状态码定义了常量比如
http.StatusContinue = 100
http.StatusOK = 200
http.StatusFound = 302
http.StatusBadRequest = 400
http.StatusUnauthorized = 401
http.StatusForbidden = 403
http.StatusNotFound = 404
http.StatusInternalServerError = 500
你可以使用`w.header().Set("Content-Type", "../..")设置头信息
比如在网页应用发送html字符串的时候在输出之前执行`w.Header().Set("Content-Type", "text/html")`
练习 15.4:扩展 http_fetch.go 使之可以从控制台读取url使用[章节12.1](12.1.md)学到的接收控制台输入的方法 [http_fetch2.go](examples/chapter_15/http_fetch2.go)
练习 15.5获取json格式的推特状态就像示例 15.9[twitter_status_json.go](examples/chapter_15/twitter_status_json.go)
## 链接
- [目录](directory.md)
- 上一章:[一个简单的网页服务器](15.2.md)
- 下一节:[写一个简单的网页应用](15.4.md)