Introduction

The http client supports obtaining and printing the raw input and output information of HTTP requests, which is convenient for debugging. The related methods are as follows:

  1. func (r *Response) Raw() string
  2. func (r *Response) RawDump()
  3. func (r *Response) RawRequest() string
  4. func (r *Response) RawResponse() string

As you can see, all methods are bound to the Response object, which means they can only be printed after the request is completed.

Usage Example

  1. package main
  2. import (
  3. "github.com/gogf/gf/v2/frame/g"
  4. "github.com/gogf/gf/v2/os/gctx"
  5. )
  6. func main() {
  7. response, err := g.Client().Post(
  8. gctx.New(),
  9. "https://goframe.org",
  10. g.Map{
  11. "name": "john",
  12. },
  13. )
  14. if err != nil {
  15. panic(err)
  16. }
  17. response.RawDump()
  18. }

After execution, the terminal output is:

  1. +---------------------------------------------+
  2. | REQUEST |
  3. +---------------------------------------------+
  4. POST / HTTP/1.1
  5. Host: goframe.org
  6. User-Agent: GoFrameHTTPClient v2.0.0-beta
  7. Content-Length: 9
  8. Content-Type: application/x-www-form-urlencoded
  9. Accept-Encoding: gzip
  10. name=john
  11. +---------------------------------------------+
  12. | RESPONSE |
  13. +---------------------------------------------+
  14. HTTP/1.1 405 Method Not Allowed
  15. Connection: close
  16. Transfer-Encoding: chunked
  17. Allow: GET
  18. Cache-Control: no-store
  19. Content-Security-Policy: frame-ancestors 'self'
  20. Content-Type: text/html;charset=UTF-8
  21. Date: Fri, 03 Dec 2021 09:43:29 GMT
  22. Expires: Thu, 01 Jan 1970 00:00:00 GMT
  23. Server: nginx
  24. ...