1 Star 0 Fork 0

trako/gentleman

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
克隆/下载
body_json.go 722 Bytes
一键复制 编辑 原始数据 按行查看 历史
trako 提交于 2024-03-14 16:53 . fix包错误导入
package main
import (
"fmt"
"gitee.com/trako/gentleman/plugins/body"
)
func main() {
// Create a new client
cli := gentleman.New()
// Define the Base URL
cli.URL("http://httpbin.org/post")
// Create a new request based on the current client
req := cli.Request()
// Method to be used
req.Method("POST")
// Define the JSON payload via body plugin
data := map[string]string{"foo": "bar"}
req.Use(body.JSON(data))
// Perform the request
res, err := req.Send()
if err != nil {
fmt.Printf("Request error: %s\n", err)
return
}
if !res.Ok {
fmt.Printf("Invalid server response: %d\n", res.StatusCode)
return
}
fmt.Printf("Status: %d\n", res.StatusCode)
fmt.Printf("Body: %s", res.String())
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/trako/gentleman.git
git@gitee.com:trako/gentleman.git
trako
gentleman
gentleman
v2.1.1

搜索帮助

D67c1975 1850385 1daf7b77 1850385