GO语言"net/http/httputil"包中"DumpResponse"函数的用法及代码示例。
用法:
func DumpResponse(resp *http.Response, body bool)([]byte, error)
DumpResponse 类似于 DumpRequest 但会转储响应。
例子:
package main
import (
"fmt"
"log"
"net/http"
"net/http/httptest"
"net/http/httputil"
)
func main() {
const body = "Go is a general-purpose language designed with systems programming in mind."
ts := httptest.NewServer(http.HandlerFunc(func(w http.ResponseWriter, r *http.Request) {
w.Header().Set("Date", "Wed, 19 Jul 1972 19:00:00 GMT")
fmt.Fprintln(w, body)
}))
defer ts.Close()
resp, err := http.Get(ts.URL)
if err != nil {
log.Fatal(err)
}
defer resp.Body.Close()
dump, err := httputil.DumpResponse(resp, true)
if err != nil {
log.Fatal(err)
}
fmt.Printf("%q", dump)
}
输出:
"HTTP/1.1 200 OK\r\nContent-Length: 76\r\nContent-Type: text/plain; charset=utf-8\r\nDate: Wed, 19 Jul 1972 19:00:00 GMT\r\n\r\nGo is a general-purpose language designed with systems programming in mind.\n"
相关用法
- GO DumpRequest用法及代码示例
- GO DumpRequestOut用法及代码示例
- GO Dumper用法及代码示例
- GO Dump用法及代码示例
- GO Duration.Hours用法及代码示例
- GO Duration.Round用法及代码示例
- GO Duration用法及代码示例
- GO Duration.Truncate用法及代码示例
- GO Duration.String用法及代码示例
- GO Duration.Minutes用法及代码示例
- GO Duration.Milliseconds用法及代码示例
- GO Duration.Seconds用法及代码示例
- GO Duration.Microseconds用法及代码示例
- GO Duration.Nanoseconds用法及代码示例
- GO DecodeLastRuneInString用法及代码示例
- GO DB.QueryRowContext用法及代码示例
- GO Date用法及代码示例
- GO DB.ExecContext用法及代码示例
- GO Dial用法及代码示例
- GO DB.BeginTx用法及代码示例
注:本文由纯净天空筛选整理自golang.google.cn大神的英文原创作品 DumpResponse。非经特殊声明,原始代码版权归原作者所有,本译文未经允许或授权,请勿转载或复制。