diff --git a/README.md b/README.md index ca8d30f..5519d1b 100644 --- a/README.md +++ b/README.md @@ -93,6 +93,7 @@ gout 是go写的http 客户端,为提高工作效率而开发 - [send raw http request](#send-raw-http-request) - [export](#export) - [generate curl command](#generate-curl-command) + - [generate curl command and send HTTP request](#generate-curl-command-and-send-http-request) - [Incoming custom * http.Client](#Incoming-custom-*http.Client) - [Using chunked data format](#Using-chunked-data-format) - [NewWithOpt](#NewWithOpt) @@ -1741,6 +1742,7 @@ Accept-Encoding: gzip ``` # export ## generate curl command +仅仅生成curl命令, 不会发送http请求 ```go package main @@ -1767,6 +1769,35 @@ func main() { fmt.Printf("%v\n", err) } +``` + +## generate curl command and send HTTP request +生成curl命令, 同时执行http请求, 在```Curl()```命令之行跟上```GenAndSend()```接口 +```go +package main + +import ( + "fmt" + "github.com/guonaihong/gout" +) + +func main() { + // 1.formdata + err := gout.GET(":1234"). + SetForm(gout.A{"text", "good", "mode", "A", "voice", gout.FormFile("./t8.go")}). + Export().Curl().GenAndSend().Do() + // output: + // curl -X GET -F "text=good" -F "mode=A" -F "voice=@./voice" "http://127.0.0.1:1234" + + // 2.json body + err = gout.GET(":1234"). + SetJSON(gout.H{"key1": "val1", "key2": "val2"}). + Export().Curl().GenAndSend().Do() + // output: + // curl -X GET -H "Content-Type:application/json" -d "{\"key1\":\"val1\",\"key2\":\"val2\"}" "http://127.0.0.1:1234" + + fmt.Printf("%v\n", err) +} ``` # Incoming custom *http.Client 使用New接口即可使用自己的http.Client对象