Ai
0 Star 1 Fork 0

shallot/Go开发工具集

加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
克隆/下载
api_post_json.go 794 Bytes
一键复制 编辑 原始数据 按行查看 历史
shallot 提交于 2024-08-22 14:58 +08:00 . 移入autohttp库。
package autohttp
import (
"context"
"encoding/json"
"net/http"
)
// POST请求,application/json
func PostJson(
ctx context.Context,
businessType string,
businessId string,
url string,
header map[string]string,
body interface{},
) (statusCode int, rspBytes []byte, err error) {
bodyData, err := json.Marshal(body)
if err != nil {
return
}
if header == nil {
header = map[string]string{}
}
if _, ok1 := header["Content-Type"]; !ok1 {
if _, ok2 := header["content-type"]; !ok2 {
header["Content-Type"] = "application/json"
}
}
item := Item{
BusinessType: businessType,
BusinessId: businessId,
Url: url,
Method: http.MethodPost,
Header: header,
Body: bodyData,
}
statusCode, rspBytes, err = apiBase(ctx, &item)
return
}
Loading...
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化
Go
1
https://gitee.com/gxsshallot/gotool.git
git@gitee.com:gxsshallot/gotool.git
gxsshallot
gotool
Go开发工具集
d05a69787598

搜索帮助