MCPcopy
hub / github.com/OpenNHP/opennhp / Request

Function Request

nhp/utils/request.go:30–56  ·  view source on GitHub ↗
(url, method string, str string, header map[string]string)

Source from the content-addressed store, hash-verified

28}
29
30func Request(url, method string, str string, header map[string]string) (string, error) {
31 payload := strings.NewReader(str)
32
33 client := &http.Client{}
34 req, err := http.NewRequest(method, url, payload)
35 if err != nil {
36 return "", err
37 }
38
39 // req.Header.Add("Content-Type", "application/json")
40 for k, v := range header {
41 req.Header.Add(k, v)
42 }
43
44 res, err := client.Do(req)
45 if err != nil {
46 return "", err
47 }
48 defer res.Body.Close()
49
50 body, err := io.ReadAll(res.Body)
51 if err != nil {
52 return "", err
53 }
54
55 return string(body), nil
56}

Callers

nothing calls this directly

Calls 2

AddMethod · 0.65
CloseMethod · 0.65

Tested by

no test coverage detected