@@ -11,6 +11,7 @@ import (
1111 "net/http"
1212
1313 "gopkg.in/inconshreveable/log15.v2"
14+ "fmt"
1415)
1516
1617var Log = log15 .New ()
@@ -41,19 +42,26 @@ type SoapFault struct {
4142 Detail string `xml:"detail,omitempty"`
4243}
4344
45+ type BasicAuth struct {
46+ Login string
47+ Password string
48+ }
49+
4450type SoapClient struct {
4551 url string
4652 tls bool
53+ auth * BasicAuth
4754}
4855
4956func (f * SoapFault ) Error () string {
5057 return f .Faultstring
5158}
5259
53- func NewSoapClient (url string , tls bool ) * SoapClient {
60+ func NewSoapClient (url string , tls bool , auth * BasicAuth ) * SoapClient {
5461 return & SoapClient {
5562 url : url ,
5663 tls : tls ,
64+ auth : auth ,
5765 }
5866}
5967
@@ -85,6 +93,9 @@ func (s *SoapClient) Call(soapAction string, request, response interface{}) erro
8593 }
8694
8795 req , err := http .NewRequest ("POST" , s .url , buffer )
96+ if s .auth != nil {
97+ req .SetBasicAuth (s .auth .Login , s .auth .Password )
98+ }
8899 req .Header .Add ("Content-Type" , "text/xml; charset=\" utf-8\" " )
89100 if soapAction != "" {
90101 req .Header .Add ("SOAPAction" , soapAction )
@@ -111,7 +122,7 @@ func (s *SoapClient) Call(soapAction string, request, response interface{}) erro
111122 Log .Warn ("empty response" )
112123 return nil
113124 }
114-
125+ fmt . Println ( string ( rawbody ))
115126 respEnvelope := & SoapEnvelope {}
116127
117128 err = xml .Unmarshal (rawbody , respEnvelope )
0 commit comments