MCPcopy
hub / github.com/silenceper/wechat / HTTPPostContext

Function HTTPPostContext

util/http.go:65–89  ·  view source on GitHub ↗

HTTPPostContext post 请求

(ctx context.Context, uri string, data []byte, header map[string]string)

Source from the content-addressed store, hash-verified

63
64// HTTPPostContext post 请求
65func HTTPPostContext(ctx context.Context, uri string, data []byte, header map[string]string) ([]byte, error) {
66 if uriModifier != nil {
67 uri = uriModifier(uri)
68 }
69 body := bytes.NewBuffer(data)
70 request, err := http.NewRequestWithContext(ctx, http.MethodPost, uri, body)
71 if err != nil {
72 return nil, err
73 }
74
75 for key, value := range header {
76 request.Header.Set(key, value)
77 }
78
79 response, err := DefaultHTTPClient.Do(request)
80 if err != nil {
81 return nil, err
82 }
83
84 defer response.Body.Close()
85 if response.StatusCode != http.StatusOK {
86 return nil, fmt.Errorf("http post error : uri=%v , statusCode=%v", uri, response.StatusCode)
87 }
88 return io.ReadAll(response.Body)
89}
90
91// PostJSONContext post json 数据请求
92func PostJSONContext(ctx context.Context, uri string, obj interface{}) ([]byte, error) {

Callers 3

GetPhoneNumberContextMethod · 0.92
HTTPPostFunction · 0.85

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…