Post performs an HTTP POST and returns the bytes and/or an error. Any non-200 return code is returned as an error.
(path string, data io.Reader)
| 191 | // Post performs an HTTP POST and returns the bytes and/or an error. Any |
| 192 | // non-200 return code is returned as an error. |
| 193 | func (p *Process) Post(path string, data io.Reader) ([]byte, error) { |
| 194 | client := &http.Client{ |
| 195 | Timeout: 600 * time.Second, |
| 196 | Transport: &http.Transport{ |
| 197 | DisableKeepAlives: true, |
| 198 | }, |
| 199 | } |
| 200 | url := fmt.Sprintf("http://%s%s", p.addr, path) |
| 201 | req, err := http.NewRequest(http.MethodPost, url, data) |
| 202 | if err != nil { |
| 203 | return nil, err |
| 204 | } |
| 205 | |
| 206 | req.Header.Add("X-Api-Key", APIKey) |
| 207 | req.Header.Add("Content-Type", "application/json") |
| 208 | |
| 209 | resp, err := client.Do(req) |
| 210 | if err != nil { |
| 211 | return nil, err |
| 212 | } |
| 213 | |
| 214 | return p.readResponse(resp) |
| 215 | } |
| 216 | |
| 217 | type Event struct { |
| 218 | ID int |
no test coverage detected