GoFrame HTTPClient-請求信息打印

2022-04-14 11:24 更新

基本介紹

?http?客戶端支持對?HTTP?請求的輸入與輸出原始信息獲取與打印,方便調(diào)試,相關(guān)方法如下:

func (r *Response) Raw() string
func (r *Response) RawDump()
func (r *Response) RawRequest() string
func (r *Response) RawResponse() string

可以看到,所有的方法均綁定在?Response?對象上,也就是說必須要請求結(jié)束后才能打印。

使用示例

package main

import (
	"github.com/gogf/gf/v2/frame/g"
	"github.com/gogf/gf/v2/os/gctx"
)

func main() {
	response, err := g.Client().Post(
		gctx.New(),
		"https://goframe.org",
		g.Map{
			"name": "john",
		},
	)
	if err != nil {
		panic(err)
	}
	response.RawDump()
}

執(zhí)行后,終端輸出為:

+---------------------------------------------+
|                   REQUEST                   |
+---------------------------------------------+
POST / HTTP/1.1
Host: goframe.org
User-Agent: GoFrameHTTPClient v2.0.0-beta
Content-Length: 9
Content-Type: application/x-www-form-urlencoded
Accept-Encoding: gzip


name=john

+---------------------------------------------+
|                   RESPONSE                  |
+---------------------------------------------+
HTTP/1.1 405 Method Not Allowed
Connection: close
Transfer-Encoding: chunked
Allow: GET
Cache-Control: no-store
Content-Security-Policy: frame-ancestors 'self'
Content-Type: text/html;charset=UTF-8
Date: Fri, 03 Dec 2021 09:43:29 GMT
Expires: Thu, 01 Jan 1970 00:00:00 GMT
Server: nginx
...


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號