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

Function PostJSONContext

util/http.go:92–118  ·  view source on GitHub ↗

PostJSONContext post json 数据请求

(ctx context.Context, uri string, obj interface{})

Source from the content-addressed store, hash-verified

90
91// PostJSONContext post json 数据请求
92func PostJSONContext(ctx context.Context, uri string, obj interface{}) ([]byte, error) {
93 if uriModifier != nil {
94 uri = uriModifier(uri)
95 }
96 jsonBuf := new(bytes.Buffer)
97 enc := json.NewEncoder(jsonBuf)
98 enc.SetEscapeHTML(false)
99 err := enc.Encode(obj)
100 if err != nil {
101 return nil, err
102 }
103 req, err := http.NewRequestWithContext(ctx, "POST", uri, jsonBuf)
104 if err != nil {
105 return nil, err
106 }
107 req.Header.Set("Content-Type", "application/json;charset=utf-8")
108 response, err := DefaultHTTPClient.Do(req)
109 if err != nil {
110 return nil, err
111 }
112 defer response.Body.Close()
113
114 if response.StatusCode != http.StatusOK {
115 return nil, fmt.Errorf("http get error : uri=%v , statusCode=%v", uri, response.StatusCode)
116 }
117 return io.ReadAll(response.Body)
118}
119
120// PostJSON post json 数据请求
121func PostJSON(uri string, obj interface{}) ([]byte, error) {

Callers 15

GetPreCodeContextMethod · 0.92
QueryAuthCodeContextMethod · 0.92
GetAuthrInfoContextMethod · 0.92
MsgCheckContextMethod · 0.92
PullUploadMethod · 0.92
GetTaskMethod · 0.92
ApplyUploadMethod · 0.92
CommitUploadMethod · 0.92

Calls 1

SetMethod · 0.65

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…