Versions Compared
compared with
Key
- This line was added.
- This line was removed.
- Formatting was changed.
ghttp
客户端支持对HTTP请求的输入与输出原始信息获取与打印,方便调试,相关方法如下:
Code Block | ||
---|---|---|
| ||
func (r *ClientResponse) Raw() string
func (r *ClientResponse) RawDump()
func (r *ClientResponse) RawRequest() string
func (r *ClientResponse) RawResponse() string |
...
可以看到,所有的方法均绑定在ClientResponse
对象上,也就是说必须要请求结束后才能打印。
使用示例
Code Block | ||
---|---|---|
| ||
package main import ( "github.com/gogf/gf/v2/frame/g" "github.com/gogf/gf/v2/os/gctx" ) func main() { response, err := g.Client().Get(gctx.New(), "https://goframe.org?name=john") if err != nil { panic(err) } response.RawDump() } |
...
执行后,终端输出为:
Code Block | ||
---|---|---|
| ||
+---------------------------------------------+ | REQUEST | +---------------------------------------------+ GET /?name=john HTTP/1.1 Host: goframe.org User-Agent: |
...
GoFrameHTTPClient v2.0.0-beta Accept-Encoding: gzip +---------------------------------------------+ | RESPONSE | +---------------------------------------------+ HTTP/1.1 200 OK Connection: close Transfer-Encoding: chunked Cache-Control: no-store Content-Security-Policy: frame-ancestors 'self' Content-Type: text/html; |
...
charset= |
...
UTF-8 Date: |
...
Fri, |
...
03 |
...
Dec |
...
2021 |
...
09: |
...
35: |
...
34 GMT |
...
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: nginx
... |
Panel | ||
---|---|---|
| ||
|