-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathsoapcli.go
More file actions
47 lines (40 loc) · 951 Bytes
/
soapcli.go
File metadata and controls
47 lines (40 loc) · 951 Bytes
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
package expertview
import (
"crypto/tls"
"io"
"io/ioutil"
"net"
"net/http"
"time"
)
const defaultTimeout = 10 * time.Second
type soapCli struct {
Timeout time.Duration
Endpoint string
InsecureSkipVerify bool
}
func (sc *soapCli) call(r io.Reader) ([]byte, error) {
req, err := http.NewRequest("POST", sc.Endpoint, r)
req.Header.Add("Content-Type", "text/xml; charset=\"utf-8\"")
req.Header.Set("User-Agent", "go-expertview/0.1")
req.Close = true
tr := &http.Transport{
TLSClientConfig: &tls.Config{
InsecureSkipVerify: sc.InsecureSkipVerify,
},
Dial: func(network, addr string) (net.Conn, error) {
timeout := sc.Timeout
if timeout == 0 {
timeout = defaultTimeout
}
return net.DialTimeout(network, addr, timeout)
},
}
client := &http.Client{Transport: tr}
res, err := client.Do(req)
if err != nil {
return nil, err
}
defer res.Body.Close()
return ioutil.ReadAll(res.Body)
}