-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathrest.go
51 lines (40 loc) · 868 Bytes
/
rest.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
package main
import (
"bytes"
"encoding/xml"
"errors"
"io/ioutil"
"net/http"
)
type RestClient struct {
}
func (r *RestClient) Send(vote Vote) error {
var err error
buf, err := xml.Marshal(vote)
if err != nil {
return err
}
req, err := http.NewRequest("POST", settings.RestUrl(), bytes.NewBuffer(buf))
if err != nil {
return err
}
//req.Header.Set("X-Custom-Header", "myvalue")
req.Header.Set("Content-Type", "application/json")
client := &http.Client{}
resp, err := client.Do(req)
if err != nil {
return err
}
defer resp.Body.Close()
parrot.Debug("response Status:" + resp.Status)
//parrot.Debug(resp.Header)
body, err := ioutil.ReadAll(resp.Body)
if err != nil {
return err
}
parrot.Debug("response Body:" + string(body))
if resp.StatusCode != 201 {
return errors.New("response Status:" + resp.Status)
}
return nil
}