MCPcopy Create free account
hub / github.com/Mrs4s/six-cli / PostJson

Method PostJson

models/httpclient.go:44–69  ·  view source on GitHub ↗
(url, body string)

Source from the content-addressed store, hash-verified

42}
43
44func (cli *SixHttpClient) PostJson(url, body string) string {
45 req, err := http.NewRequest("POST", url, strings.NewReader(body))
46 if err != nil {
47 return ""
48 }
49 defer req.Body.Close()
50 if cli.QingzhenToken != "" {
51 req.Header["Authorization"] = []string{"Bearer " + cli.QingzhenToken}
52 }
53 req.Header["User-Agent"] = []string{"Qingzhen-cli:0.1"}
54 req.Header["Content-Type"] = []string{"application/json"}
55 resp, err := cli.client.Do(req)
56 if err != nil {
57 return ""
58 }
59 defer resp.Body.Close()
60 b, err := ioutil.ReadAll(resp.Body)
61 if err != nil {
62 return ""
63 }
64 token, ok := resp.Header["Authorization"]
65 if ok && len(token) > 0 {
66 cli.QingzhenToken = token[0]
67 }
68 return string(b)
69}
70
71func (cli *SixHttpClient) GetBytes(url string) ([]byte, error) {
72 req, err := http.NewRequest("GET", url, nil)

Callers 3

PostJsonObjectMethod · 0.95
CopyFileMethod · 0.80
LoginWithUsernameOrPhoneFunction · 0.80

Calls

no outgoing calls

Tested by

no test coverage detected