mirror of
https://github.com/unknwon/the-way-to-go_ZH_CN.git
synced 2025-11-13 09:16:10 +08:00
Update 15.3.md
This commit is contained in:
@@ -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)
|
||||
|
||||
Reference in New Issue
Block a user