You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
naza/pkg/nazahttp/post.go

31 lines
724 B
Go

// Copyright 2020, Chef. All rights reserved.
// https://github.com/q191201771/naza
//
// Use of this source code is governed by a MIT-style license
// that can be found in the License file.
//
// Author: Chef (191201771@qq.com)
package nazahttp
import (
"bytes"
"encoding/json"
"net/http"
)
// @param url 地址
// @param info 需要序列化的结构体
// @param client 注意如果为nil则使用http.DefaultClient
func PostJson(url string, info interface{}, client *http.Client) (*http.Response, error) {
j, err := json.Marshal(info)
if err != nil {
return nil, err
}
b := bytes.NewBuffer(j)
if client == nil {
client = http.DefaultClient
}
return client.Post(url, HeaderFieldContentType, b)
}