MCPcopy Create free account
hub / github.com/evilsocket/shellz / Request

Method Request

plugins/http.go:42–95  ·  view source on GitHub ↗
(method string, uri string, headers map[string]string, form map[string]string)

Source from the content-addressed store, hash-verified

40}
41
42func (c httpPackage) Request(method string, uri string, headers map[string]string, form map[string]string) httpResponse {
43 var reader io.Reader
44 if form != nil {
45 data := url.Values{}
46 for k, v := range form {
47 data.Set(k, v)
48 }
49 reader = bytes.NewBufferString(data.Encode())
50 }
51
52 req, err := http.NewRequest(method, uri, reader)
53 if err != nil {
54 return httpResponse{Error: err}
55 }
56
57 if form != nil {
58 req.Header.Set("Content-Type", "application/x-www-form-urlencoded")
59 }
60
61 for name, value := range headers {
62 req.Header.Add(name, value)
63 }
64
65 transport := &http.Transport{}
66 client := &http.Client{Transport: transport}
67
68 if c.proxy.Address != "" {
69 if dialer, err := proxy.SOCKS5("tcp", c.proxy.String(), nil, proxy.Direct); err != nil {
70 return httpResponse{
71 Error: err,
72 }
73 } else {
74 transport.Dial = dialer.Dial
75 }
76 }
77
78 resp, err := client.Do(req)
79 if err != nil {
80 return httpResponse{Error: err}
81 }
82 defer resp.Body.Close()
83
84 raw, err := ioutil.ReadAll(resp.Body)
85 if err != nil {
86 return httpResponse{Error: err}
87 }
88
89 return httpResponse{
90 Error: nil,
91 Response: resp,
92 Raw: raw,
93 Body: string(raw),
94 }
95}
96
97func (c httpPackage) Get(url string, headers map[string]string) httpResponse {
98 return c.Request("GET", url, headers, nil)

Callers 2

GetMethod · 0.95
PostMethod · 0.95

Calls 2

CloseMethod · 0.65
StringMethod · 0.45

Tested by

no test coverage detected