|
62 | 62 | * goroutine concurrent safe
|
63 | 63 | * Resty Client trace, see [Client.EnableTrace](https://pkg.go.dev/github.com/go-resty/resty/v2#Client.EnableTrace) and [Request.EnableTrace](https://pkg.go.dev/github.com/go-resty/resty/v2#Request.EnableTrace)
|
64 | 64 | * Since v2.4.0, trace info contains a `RequestAttempt` value, and the `Request` object contains an `Attempt` attribute
|
| 65 | + * Supports `GenerateCurlCommand`(**You should turn on `EnableTrace`**, otherwise the curl command will not contain the body) |
65 | 66 | * Debug mode - clean and informative logging presentation
|
66 | 67 | * Gzip - Go does it automatically also resty has fallback handling too
|
67 | 68 | * Works fine with `HTTP/2` and `HTTP/1.1`
|
@@ -122,18 +123,19 @@ The following samples will assist you to become as comfortable as possible with
|
122 | 123 | import "github.com/go-resty/resty/v2"
|
123 | 124 | ```
|
124 | 125 |
|
125 |
| -#### Simple GET |
| 126 | +#### Simple POST |
| 127 | +>Refer: [debug_curl_test.go](https://github.com/go-resty/resty/blob/v2/examples/debug_curl_test.go) |
126 | 128 |
|
127 | 129 | ```go
|
128 | 130 | // Create a Resty Client
|
129 | 131 | client := resty.New()
|
130 | 132 |
|
131 | 133 | resp, err := client.R().
|
132 |
| - EnableTrace(). |
133 |
| - Get("https://httpbin.org/get") |
| 134 | + EnableTrace(). // You should turn on `EnableTrace`, otherwise the curl command will not contain the body |
| 135 | + SetBody(map[string]string{"name": "Alex"}). |
| 136 | + Post("https://httpbin.org/post") |
134 | 137 | curlCmdExecuted := resp.Request.GenerateCurlCommand()
|
135 | 138 |
|
136 |
| - |
137 | 139 | // Explore curl command
|
138 | 140 | fmt.Println("Curl Command:\n ", curlCmdExecuted+"\n")
|
139 | 141 |
|
@@ -166,27 +168,35 @@ fmt.Println(" RemoteAddr :", ti.RemoteAddr.String())
|
166 | 168 |
|
167 | 169 | /* Output
|
168 | 170 | Curl Command:
|
169 |
| - curl -X GET -H 'User-Agent: go-resty/2.12.0 (https://github.com/go-resty/resty)' https://httpbin.org/get |
| 171 | + curl -X POST -H 'Content-Type: application/json' -H 'User-Agent: go-resty/2.14.0 (https://github.com/go-resty/resty)' -d '{"name":"Alex"}' https://httpbin.org/post |
170 | 172 |
|
171 | 173 | Response Info:
|
172 | 174 | Error : <nil>
|
173 | 175 | Status Code: 200
|
174 | 176 | Status : 200 OK
|
175 | 177 | Proto : HTTP/2.0
|
176 | 178 | Time : 457.034718ms
|
177 |
| - Received At: 2020-09-14 15:35:29.784681 -0700 PDT m=+0.458137045 |
| 179 | + Received At: 2024-08-09 13:02:57.187544 +0800 CST m=+1.304888501 |
178 | 180 | Body :
|
179 |
| - { |
180 |
| - "args": {}, |
181 |
| - "headers": { |
182 |
| - "Accept-Encoding": "gzip", |
183 |
| - "Host": "httpbin.org", |
184 |
| - "User-Agent": "go-resty/2.4.0 (https://github.com/go-resty/resty)", |
185 |
| - "X-Amzn-Trace-Id": "Root=1-5f5ff031-000ff6292204aa6898e4de49" |
186 |
| - }, |
187 |
| - "origin": "0.0.0.0", |
188 |
| - "url": "https://httpbin.org/get" |
189 |
| - } |
| 181 | + { |
| 182 | + "args": {}, |
| 183 | + "data": "{\"name\":\"Alex\"}", |
| 184 | + "files": {}, |
| 185 | + "form": {}, |
| 186 | + "headers": { |
| 187 | + "Accept-Encoding": "gzip", |
| 188 | + "Content-Length": "15", |
| 189 | + "Content-Type": "application/json", |
| 190 | + "Host": "httpbin.org", |
| 191 | + "User-Agent": "go-resty/2.14.0 (https://github.com/go-resty/resty)", |
| 192 | + "X-Amzn-Trace-Id": "Root=1-66b5a301-567c83c86562abd3092f5e19" |
| 193 | + }, |
| 194 | + "json": { |
| 195 | + "name": "Alex" |
| 196 | + }, |
| 197 | + "origin": "0.0.0.0", |
| 198 | + "url": "https://httpbin.org/post" |
| 199 | +} |
190 | 200 |
|
191 | 201 | Request Trace Info:
|
192 | 202 | DNSLookup : 4.074657ms
|
|
0 commit comments